Installing OR-Tools Java from Source on Linux

Stay organized with collections Save and categorize content based on your preferences.

Introduction

This guide explains how to install OR-Tools from source, with support for Java, on Linux.

Unless you plan to modify the source code or use a third-party solver with OR-Tools, we recommend the binary installation.

Although these instructions might also work on other Linux variants, we have only tested them on machines meeting the following requirements:

  • Alpine Edge 64-bit (x86_64)
  • Centos 7 64-bit (x86_64)
  • Centos Stream 8 64-bit (x86_64)
  • Debian 10 (buster) 64-bit (x86_64)
  • Debian 11 (bullseye) 64-bit (x86_64)
  • Fedora 33 64-bit (x86_64)
  • Fedora 34 64-bit (x86_64)
  • OpenSuse Leap 64-bit (x86_64)
  • Ubuntu 18.04 LTS 64-bit (x86_64)
  • Ubuntu 20.04 LTS 64-bit (x86_64)
  • Ubuntu 22.04 LTS 64-bit (x86_64)

Prerequisites

The following sections describe the prerequisites for installing OR-Tools.

C++ tools

To install C++ tools, open a terminal window and enter:

Alpine Edge

apk add git build-base linux-headers cmake xfce4-dev-tools

Centos 8

yum groupinstall 'Development Tools'
yum -y install pkgconfig

Debian 10

sudo apt-get -y install git wget pkg-config build-essential cmake autoconf libtool zlib1g-dev lsb-release

Ubuntu 22.04 LTS

sudo apt-get -y install git wget pkg-config build-essential cmake autoconf libtool zlib1g-dev lsb-release

Ubuntu 20.04 LTS

sudo apt-get -y install git wget pkg-config build-essential cmake autoconf libtool zlib1g-dev lsb-release

Ubuntu 18.04 LTS

sudo apt-get -y install git wget pkg-config build-essential cmake autoconf libtool zlib1g-dev lsb-release

SWIG

To install SWIG, open a terminal window and enter:

Alpine Edge

sudo apk add swig

Centos 8

sudo dnf install swig

Debian 10

sudo apt install swig

Ubuntu 22.04 LTS

sudo apt install swig

Ubuntu 20.04 LTS

sudo apt install swig

Ubuntu 18.04 LTS

sudo apt install swig

Java JDK >= 8.0

To install the Java JDK version 8.0 or higher, open a terminal window and enter:

Alpine Edge

sudo apk add openjdk8
export JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk

Centos 8

sudo dnf install java-1.8.0-openjdk java-1.8.0-openjdk-devel

Debian 10

sudo apt install default-jdk
export JAVA_HOME=/usr/lib/jvm/default-java

Ubuntu 22.04 LTS

sudo apt install default-jdk
export JAVA_HOME=/usr/lib/jvm/default-java

Ubuntu 20.04 LTS

sudo apt install default-jdk
export JAVA_HOME=/usr/lib/jvm/default-java

Ubuntu 18.04 LTS

sudo apt install default-jdk
export JAVA_HOME=/usr/lib/jvm/default-java

Maven >= 3.3

To install Maven version 3.3 or higher, open a terminal window and enter:

Alpine Edge

sudo apk add maven

Centos 8

sudo dnf install maven

Debian 10

sudo apt install maven

Ubuntu 22.04 LTS

sudo apt install maven

Ubuntu 20.04 LTS

sudo apt install maven

Ubuntu 18.04 LTS

sudo apt install maven

You can test Maven is correctly installed and can find java using the following command:

mvn -v

Download the source code

There are two distinct branches of the OR-Tools source code on GitHub: stable and main.

The stable branch has been thoroughly tested and should work flawlessly on all supported platforms.
The main branch is where the latest updates and improvements have been applied; it's more current, but less stable.

Download the stable source code

You can get the stable source code for OR-Tools in either of the following ways:

  • Clone the stable branch by entering:

    git clone https://github.com/google/or-tools
    
  • Download the latest release in a compressed file, by clicking the Clone or download button in GitHub. image of clone or download button

Download the main source code

To retrieve the source code from the main branch, enter:

git clone -b main https://github.com/google/or-tools

Download previous releases

You can get the source code for previous releases in either of the following ways:

  • Download a previous release from the GitHub release page.
  • Assuming you have already created a local repository (by git clone), you can check out a specific release using a Git tag. For example, to work with the v9.4 release instead of the main branch, enter the following commands in your local repo:

    git fetch --all --tags --prune
    git checkout tags/v9.4 -v v9.4
    

Build third parties

Before building OR-Tools, you'll need to build the required third party software.

Open a terminal and navigate to the directory where you extracted the files. Then enter:

make third_party

Using SCIP

Since v7.8, SCIP is now integrated so you won't have to install it manually.

Using Gurobi

Gurobi is now pre-integrated. When needed, at runtime, OR-Tools will search for the Gurobi shared library in the default install path of the Gurobi installers on MAC OS X and Windows, or by using the GUROBI_HOME environment variable.

Using an optional third-party MIP solver

You can also use OR-Tools with any of the following optional third-party MIP solvers whose support is disabled by default:

To configure OR-Tools to use one of these solvers, do the following steps:

  1. Install the optional solver following the vendor instruction.
  2. Open Makefile.local and add the path to the directory where you have installed the solver. For example, for CPLEX you would add this:
    UNIX_CPLEX_DIR=cplex/install/dir

Build the source code

To build the source code, open a terminal and navigate to the directory where you extracted the files. Then enter the following command to compile OR-Tools:

make java

Test the source code

You can check that everything is running correctly by entering:

make test_java

This runs a selection of examples for OR-Tools. If all the examples run successfully, you are ready to get started with OR-Tools.

Cleaning the build files

If you need to re-install OR-Tools, the command:

make clean_third_party

will remove all compiled dependencies and Makefile.local. This can be useful for resetting to a clean state.

Then re-enter the commands:

make third_party
make java