Dealing with Catalina III

As of January 1, 2020, the Catalina version of the Mac OSX operating system prevents the recommended C++ toolchain installer by @coatless from running. If you try, you will see something like

To get around this problem at the moment, you need to follow the instructions starting at “Manual Install Guide” at

If you have questions, follow up below. Then, you will probably need to do a

install.packages('rstan", type = "source")

in a clean R session.


The RStan installation instructions here need to be updated.

It is currently possible on a mac with catalina to run install.packages("rstan", repos = "", dependencies = TRUE), have it not ask you to compile from source, and have pkgbuild::has_build_tools(debug = TRUE) return TRUE and still have rstan compilation problems.

I now know this because of a group of undergraduates chasing me with pitchforks.

Is the correct advice for all cases to do the manual install guide above and install from source?


Yes. Unfortunately, the pkgbuild::has_build_tools function tests whether it can compile a hello world program in C, which Catalina with Xcode can do. However, Catalina with Xcode miscompiles C++ so as to mispropagate exceptions under R, so most non-trivial Stan programs will terminate the MCMC without returning results. That is why we use LLVM clang++ rather than Xcode clang++ until Apple started blocking our toolchain installer starting January 1 because it is not a certified Apple Developer application.

If the people would put down their pitchforks and read the wiki, it does eventually say

If this line ultimately returns TRUE , then your C++ toolchain is properly installed and you can jump to the next section, unless you have the Catalina version of the Mac OSX operating system (see 3 below).

3 If you use a Mac, a link will appear but do not click on it. Instead go here

which takes you to a page that says

We recommend using the macOS R toolchain installer for pre-Catalina versions of the operating system. If you have Catalina, then you need to follow these instructions starting from “Manual Install Guide” to download and configure your C++ toolchain.

Suggestions are more than welcome as to how to reword that or anyone can just edit the wiki pages themselves. But I don’t know how better to explain in a few words why the only way forward at the moment is so messed up on Macs.


I might make a specific “If you have Catalina” section tomorrow.

1 Like

I installed rstan on Catalina today following all previous instructions. Everything works perfectly fine and straightforward if I simply ignore the extra Makevars component in the “Manual Install Guide”:

Note: If you are on macOS Mojave (10.14) or higher, you will need to add into ~/.R/Makevars a set of compilation flags.

mkdir -p ~/.R

# Fill with appropriate flag statements
cat <<- EOF > ~/.R/Makevars
# clang: start
CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

SHLIB_CXXLDFLAGS+=-Wl,-rpath,\${R_HOME}/lib \${R_HOME}/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,\${R_HOME}/lib \${R_HOME}/lib/libc++abi.1.dylib
# clang: end

What does your makevars look like?

CXX14FLAGS=-O3 -march=native -mtune=native
CXX14FLAGS += -arch x86_64 -ftemplate-depth-256
And it works fine without those extra flags.


I’m trying to install Rstan on a new Mac with Catalina. I tried following the directions on Github, which were a departure from previous installations that specifically referenced Xtools.

I confess that after following multiple links from the above messages, opening the Terminal and trying to supply recommended commands … I’m not still not able to run a Stan model.

By chance, is there a step-by-step Catalina instruction guide in the works?

Catalina (mis)behaves different ways for different people. But the procedure is basically to install the toolchain by circumventing the security measures with a Ctrl-click to open it. And then see what, if anything, goes wrong. Sometimes it involves a

xcode-select --install

in the Terminal app or the Terminal tab of RStudio. Sometimes something else.


It works for me. Thank you very much !
OS Catalina 10.15.3
R version 3.6.2 (2019-12-12) – “Dark and Stormy Night”
Copyright © 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

Hi leomarameo7,

Can you explain the steps you followed to get it working?


Hi Jeremy,

Well, I opened OS Terminal. And then I wrote as follow:
mkdir -p ~/.R
cat <<- EOF > ~/.R/Makevars

CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

SHLIB_CXXLDFLAGS+=-Wl,-rpath,${R_HOME}/lib ${R_HOME}/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,${R_HOME}/lib ${R_HOME}/lib/libc++abi.1.dylib


1 Like

Thanks, @leomarameo7.

It looks like I’ve had success by doing the same. I can now estimate a Stan model.

I’ve been trying all kinds of combinations, so I’m not sure if I can summarize exactly what should be done. But this seems to work by:

  1. Downloading and installing the rtools package from the link in the opening message of this thread.
  2. Then open Terminal and enter the changes to the Markvars that @yuling recommended.

That seems to work, but maybe I’m overlooking something.

The strange thing, though, is that I continue to get a prompt about the installation of rtools:

And yet the models estimate if I dismiss the prompt. Dismissing the prompt will be a minor nuisance when it’s time to estimate a model, but at least I’m back in business.

It should not normally be asking you to keep reinstalling the build tools. What does it say when you do in a fresh R session

pkgbuild::has_build_tools(debug = TRUE)



First it throws the same prompt for reinstalling.

Then when I click “no”, it comes back with:

pkgbuild::has_build_tools(debug = TRUE)

What about

pkgbuild::has_compiler(debug = TRUE)


Lots of syntax, concluding with:

In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Dense:1:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
#include <complex>
3 errors generated.
make: *** [foo.o] Error 1



is 2.19.2 ?


OK. Try a

install.packages("StanHeaders", type = "source")