This page gives instructions of how to build and install the xgboost package from scratch on various systems. It consists of two steps:
- Fist build the shared library from the C++ codes (
libxgboost.so
for linux/osx andlibxgboost.dll
for windows).- Exception: for R-package installation please directly refer to the R package section.
- Then install the language packages (e.g. Python Package).
Important the newest version of xgboost uses submodule to maintain packages. So when you clone the repo, remember to use the recursive option as follows.
git clone --recursive https://github.com/dmlc/xgboost
For windows users who uses github tools, you can open the git shell, and type the following command.
git submodule init
git submodule update
Please refer to Trouble Shooting Section first if you had any problem during installation. If the instructions do not work for you, please feel free to ask questions at xgboost/issues, or even better to send pull request if you can fix the problem.
Our goal is to build the shared library:
- On Linux/OSX the target library is
libxgboost.so
- On Windows the target libary is
libxgboost.dll
The minimal building requirement is
- A recent c++ compiler supporting C++ 11 (g++-4.6 or higher)
We can edit make/config.mk
to change the compile options, and then build by
make
. If everything goes well, we can go the specific language installation section.
On Ubuntu, one build xgboost by
Then build xgboost
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; make -j4
On Ubuntu OSX, one build xgboost by
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; cp make/minimum.mk ./config.mk; make -j4
This build xgboost without multi-threading, because by default clang in OSX does not come with open-mp. See the following paragraph for OpenMP enabled xgboost.
Here is the complete solution to use OpenMP-enabled compilers to install XGBoost.
Obtain gcc-5.x.x with openmp support by brew install gcc --without-multilib
. (brew
is the de facto standard of apt-get
on OS X. So installing HPC separately is not recommended, but it should work.)
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; cp make/config.mk ./config.mk; make -j4
You need to first clone the xgboost repo with recursive option clone the submodules. If you are using github tools, you can open the git-shell, and type the following command.
git submodule init
git submodule update
XGBoost support both build by MSVC or MinGW. Here is how you can build xgboost library using MinGW.
Build with mingw
cp make/mingw64.mk config.mk; make -j4
The MSVC build for new version is not yet updated.
The configuration of xgboost can be modified by config.mk
- modify configuration on various distributed filesystem such as HDFS/Amazon S3/...
- First copy make/config.mk to the project root, on which any local modification will be ignored by git, then modify the according flags.
The python package is located at python-package. There are several ways to install the package:
-
Install system-widely, which requires root permission
cd python-package; sudo python setup.py install
You will however need Python
distutils
module for this to work. It is often part of the core python package or it can be installed using your package manager, e.g. in Debian usesudo apt-get install python-setuptools
NOTE: If you recompiled xgboost, then you need to reinstall it again to make the new library take effect
-
Only set the environment variable
PYTHONPATH
to tell python where to find the library. For example, assume we clonedxgboost
on the home directory~
. then we can added the following line in~/.bashrc
It is recommended for developers who may change the codes. The changes will be immediately reflected once you pulled the code and rebuild the project (no need to callsetup
again)export PYTHONPATH=~/xgboost/python-package
-
Install only for the current user.
cd python-package; python setup.py develop --user
You can install R package from cran just like other packages, or you can install from our weekly updated drat repo:
install.packages("drat", repos="https://cran.rstudio.com")
drat:::addRepo("dmlc")
install.packages("xgboost", repos="http://dmlc.ml/drat/", type = "source")
For OSX users, single threaded version will be installed, to install multi-threaded version. First follow Building on OSX to get the OpenMP enabled compiler, then:
-
Set the
Makevars
file in highest piority for R.The point is, there are three
Makevars
:~/.R/Makevars
,xgboost/R-package/src/Makevars
, and/usr/local/Cellar/r/3.2.0/R.framework/Resources/etc/Makeconf
(the last one obtained by runningfile.path(R.home("etc"), "Makeconf")
in R), andSHLIB_OPENMP_CXXFLAGS
is not set by default!! After trying, it seems that the first one has highest piority (surprise!).Then inside R, run
install.packages("drat", repos="https://cran.rstudio.com") drat:::addRepo("dmlc") install.packages("xgboost", repos="http://dmlc.ml/drat/", type = "source")
-
Compile failed after
git pull
Please first update the submodules, clean all and recompile:
git submodule update && make clean_all && make -j4
-
Compile failed after
config.mk
is modified Need to clean all first:make clean_all && make -j4
-
Makefile: dmlc-core/make/dmlc.mk: No such file or directory We need to recusrively clone the submodule, you can do:
git submodule init git submodule update
Alternatively, do another clone
git clone https://github.com/dmlc/xgboost --recursive