Rstan after updating to Mac Monterey (Intel Mac) can't find command line tools

Just gone through the annual pre-term updating of OS and software and none of the solutions suggested here and on stackexchange worked. Having finally got it working, I thought I’d leave a post in case others had the same issues as I did.

I took the following steps:

  1. Upgraded to Monterey 12.5
  2. Updated Xcode via the App Store (13.4.1)
  3. Xcode prompted me to download and install the command line tools (which I did)
  4. Updated R (4.2.1)
  5. Updated R studio (2022.07.01)

On opening Rstudio again, the popup message (I’m paraphrasing here) “git needs the command line tools, install now?”. I figured they were installed (I waited 15 minutes and it said it had worked), so I canceled and tried to install Rstan following the instructions.

First, the MacOS toolchain failed to install but elsewhere on here others have said this doesn’t matter. When I tried to install.packages(“rstan”), the errors couldn’t find ‘make’ and then the popup about getting the command line tools again. This time I did try reinstalling the command line tools (a couple of times) and it didn’t work. I had the same errors compiling a simple “helloworld.cpp” detailed here.

Following the instructions to get Rcpp working here, checking which c++ compiler was there gave

(base) Daniels-MacBook-Pro:~ danielwilliamson$ gcc --version sh: line 1: 5305 Bus error: 10 /Users/danielwilliamson/Downloads/ -sdk /Users/danielwilliamson/Downloads/ -find gcc 2> /dev/null gcc: error: sh -c '/Users/danielwilliamson/Downloads/ -sdk /Users/danielwilliamson/Downloads/ -find gcc 2> /dev/null' failed with exit code 35328: (null) (errno=Invalid argument) xcode-select: Failed to locate 'gcc', requesting installation of command line developer tools.

The solution was to open Xcode, go to Preferences -> Locations and to notice that the box next to Command Line Tools was blank. I selected the only option Xcode 13.41.1 (13F100) and then everything worked fine (I still needed to follow the instructions on installing gfortran from the “get Rcpp working” post linked above). I seems that this update of Xcode with Monterey does not automatically point to the command line tools after installation. The fix is much simpler than others I’ve seen so I thought worth sharing.

Rstan and brms both now work fine and we’re ready for the new academic year!

Glad to hear it, and thanks for sharing what worked, @BayesExeter.

The Mac upgrades for Xcode are terrible in that they make you separately turn on the command-line tools each time. I have no idea why they do this, but it’s been a thorn in our side since version 1.0.