Installing OR-Tools Java from Source on Linux

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:

  • Ubuntu 19.10/18.04/16.04 64-bit (x86_64)
  • Debian 9.4 (stretch) 64-bit (x86_64)
  • Centos 7 64-bit (x86_64)

Prerequisites

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

C++ tools

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

Centos 7

yum groupinstall 'Development Tools'
yum -y install pkgconfig

Debian 9

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

Ubuntu 19.10

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

Ubuntu 18.04

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

Ubuntu 16.04

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:

Centos 7

wget "https://downloads.sourceforge.net/project/swig/swig/swig-3.0.12/swig-3.0.12.tar.gz"
tar xvf swig-3.0.12.tar.gz && rm swig-3.0.12.tar.gz
cd swig-3.0.12 && ./configure --prefix=/usr && make -j 4
make install
cd .. && rm -rf swig-3.0.12

Debian 9

sudo apt-get -y install swig

Ubuntu 19.10

sudo apt-get -y install swig

Ubuntu 18.04

sudo apt-get -y install swig

Ubuntu 16.04

sudo apt-get -y install swig

Java JDK >= 7.0

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

Centos 7

yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

Debian 9

sudo apt-get -y install default-jdk

Ubuntu 19.10

sudo apt-get -y install default-jdk

Ubuntu 18.04

sudo apt-get -y install default-jdk

Ubuntu 16.04

sudo apt-get -y install default-jdk

Download the source code

There are two distinct branches of the OR-Tools source code on GitHub: stable and master. The stable branch has been thoroughly tested and should work flawlessly on all supported platforms. The master branch is where the latest updates and improvements have been applied; it's more current, but less stable.

Download the stable source code

To get the stable source code for OR-Tools, clone the stable branch from GitHub or download the latest release in a compressed file. You can do so by clicking the Clone or download button in GitHub.

Download the master source code

To retrieve the source code from the master branch, enter

git clone -b master 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 v7.4 release instead of the master branch, enter the following commands in your local repo:
    git fetch --all --tags --prune>
    git checkout tags/v7.2 -b v7.2>

Build the source code

To build the source code:

  1. Open a terminal and navigate to the directory where you extracted the files. Then enter the following command:
    make third_party
  2. To use a third party solver, open Makefile.local in the main or-tools directory, and add the path to the directory where you installed the solver. For example, for SCIP you would add this:
    UNIX_SCIP_DIR=scip/install/dir
  3. Compile OR-Tools by entering
    make java
  4. You can check that everything is running correctly by entering
    make test_java
  5. This runs a selection of examples for OR-Tools. If all the examples run successfully, you are ready to get started with OR-Tools.

Using a third-party solver

You can use OR-Tools with any of the following third-party solvers:

If you have already installed OR-Tools and want to configure it to use one of these solvers, do the following steps:

  1. Open a terminal and navigate to the or-tools directory. Then enter the following command:
    make third_party
  2. Open Makefile.local and add the path to the directory where you installed the solver. For example, for SCIP you would add this:
    UNIX_SCIP_DIR=scip/install/dir
  3. Compile OR-Tools by entering
    make clean
    make all

Install the SCIP Optimization Suite

To install the SCIP Optimization Suite on Linux, do the following steps:

  1. Download the SCIP archive and unpack it.
  2. Navigate to the top level of the unpacked archive and enter the following commands:
    mkdir build
    cd build
    cmake -DCMAKE_INSTALL_PREFIX=scip/install/dir -DGMP=false -DZIMPL=false -DTPI=tny -DPARASCIP=true ..
    make
    make install

After the installation is complete, follow the instructions in Using a third-party solver.

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