Skip to content

Instantly share code, notes, and snippets.

@duynguyenhoang
Last active March 7, 2018 06:50
Show Gist options
  • Select an option

  • Save duynguyenhoang/7a3439078353d8d7f108a7ea472c5c51 to your computer and use it in GitHub Desktop.

Select an option

Save duynguyenhoang/7a3439078353d8d7f108a7ea472c5c51 to your computer and use it in GitHub Desktop.
#!/bin/bash
# for setup on MacOS: https://www.ibm.com/developerworks/community/blogs/jfp/entry/Installing_XGBoost_on_Mac_OSX?lang=en
# http://stackoverflow.com/questions/40942893/how-to-install-xgboost-on-osx-with-multi-threading
# MacOS's default c++ compiler (OpenMP) doesn't support multithreading, so to get the performance boost we need to
# build xgboost from source with g++, and install it using devtools in R.
# this script sets up xgboost on an Ubuntu AWS cluster. I'm using a c4.4xlarge at the moment.
# RUN AS SUDO - TO INSTALL PACKAGES, R NEEDS ROOT ACCESS
cd ~
sudo apt-get update
sudo apt-get install libsnappy-dev python-pip build-essential libcurl4-openssl-dev libxml2-dev libssl-dev snappy -y # dependencies
# install gcc-6
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get install gcc-6 g++-6 -y
# install r-base and r-base-dev directly from CRAN, Ubuntu Software Center is unfortunately always out of date
sudo echo "deb http://cran.rstudio.com/bin/linux/ubuntu xenial/" | sudo tee -a /etc/apt/sources.list
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -
sudo apt-get update
sudo apt-get install r-base r-base-dev -y
# clone xgboost from git repo
git clone --recursive https://github.com/dmlc/xgboost
# set c++ compiler to gcc-6 for multithreading support
sed -ie "s/# export CC = gcc/export CC = gcc-6/g" xgboost/make/config.mk
sed -ie "s/# export CXX = g++/export CXX = g++-6/g" xgboost/make/config.mk
# build xgboost
cd xgboost
cp make/config.mk .
make -j16
# update R, install devtools, and finally install xgboost
sudo apt install libssl-dev libcurl4-openssl-dev -y
sudo R -q -e "install.packages(c('curl', 'httr', 'git2r', 'devtools'), repos='http://cran.rstudio.com/')"
sudo R -q -e "devtools::install('R-package')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment