Installing lightGBM on Macos Catalina

Roel M. Hogervorst


Categories: r Tags: lightgbm boostedtreemethods howto 100DaysToOffload

In this walkthrough I install lightgbm on the latest version of R on an older model macBook Pro with Macos Catalina 10.15.5 and I’m using homebrew.

The world of boosted tree models is growing over the past 4 years, the first revolution was with ‘XGBoost’ (eXtreme Gradient Boosting) in 2016, followed by ‘lightGBM’ (or LGBM) from January 2017 and later that year ‘catboost’. To use these C++ libraries in R you have to install them, and that process is slightly different for different architectures.


I’m also using the amazing RSwitch tool for the Mac to switch R versions: from 4.1.0 “experimental version”, to the latest stable version R 4.0.2 ‘Taking off again’ and an older version before that R 3.6.3 (2020-02-29) ‘Holding the Windsock’. I’m trying to install this library on all R versions, but if you use one version of R, this RSwitch tool is not necessary.

I’m mentioning all this because sometimes these things are really difficult to debug under different operating systems, and different R versions. For work I installed lightGBM on a macbook a year ago, and it was a lot more work then.


I’m following the instructions at and you should too.

First I download the code to my computer:

git clone --recursive

I deleted the lightGBM folder and re ran the git clone command.

Continuing the installation: going into the lightGBM folder and executing the build_r.R script.

cd LightGBM
Rscript build_r.R

And a failure, I do not have openMP (a multithreading library) installed brew install libomp. I did have it installed, it seems, but it wasn’t linked brew link --overwrite libomp. This was a bit aggressive, it overwrites all links to libomp. I may have broken things later, but the installation continues and is successful.

(Re)start your R session and check if you can load the library library(lightgbm).

Installing on multiple R versions using RSwitch

I than used RSwitch to switch R version to an older version of R and reran the Rscript build_r.R command in the same folder. The process reruns the installation and because RSwitch switches the R version the package is now installed in the older R version location: the script spews out * installing to library ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library’

(Re)start your R session and check if you can load the library library(lightgbm). once finished and verified I switch to R3.6 and rerun the script again. It now installs in * installing to library ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library’

And you are done.

How to install lightgbm with renv

renv builds a separate library for your project. This is cool, because it allows you to use different packages that do not influence each other. However starting a new project with renv does not have lightgbm installed.

I’ve found the easiest is to use setwd() in your R console to move to the LightGBM folder and then ssource("build_r.R") this will build the package again and place it in the correct library.


I thought there would be issues with different versions of R, but the main issues are related to architecture: system libraries that you have to install on macos. After this installation the installation of the R wrapper is not really a big issue anymore, at least not for R 3.6, 4.0 and 4.1 (at the time of writing).


I’m publishing this post too as part of 100 Days To Offload. You can join in yourself by visiting, post - 16/100

Find other posts tagged #100DaysToOffload here