XGBoosting Home | About | Contact | Examples

Build and Install XGBoost From Source

While installing XGBoost using pip is convenient for most users, there are situations where building from source is necessary or advantageous.

Building XGBoost from source provides flexibility to customize the build configuration and ensures compatibility with your specific system environment.

This example will guide you through the process of building and installing XGBoost from source, step by step.

First, clone the XGBoost repository from GitHub:

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost

Next, install the necessary build dependencies. For Ubuntu/Debian systems, run:

sudo apt-get install -y cmake make gcc g++

For macOS, install the dependencies using Homebrew:

brew install cmake libomp

Now, build the package using cmake and make:

mkdir build
cd build
cmake ..
make -j4

The -j4 flag specifies the number of parallel threads to use during the build process. Adjust this value based on your system’s capabilities.

After the build completes successfully, install the built package using pip:

cd ..
cd python-package
pip install -e .

The -e flag installs the package in “editable” mode, which allows you to make changes to the source code without reinstalling the package.

If you encounter any issues during the build process, ensure that you have all the required dependencies installed and that your system meets the minimum requirements for building XGBoost.

To update an existing installation that was built from source, simply pull the latest changes from the GitHub repository and rebuild the package:

git pull
cd build
make clean
make -j4
pip install -e .

By building XGBoost from source, you have full control over the build configuration and can optimize the package for your specific needs. This can be particularly useful when working with large datasets or when deploying XGBoost in production environments.

See Also