I've recently been having problems with compiling packages for R. I'm not sure of the causes but one possibility is that there are a couple of different versions of gcc on my MacBook Pro. When I type which gcc in a terminal window it returns /usr/bin/gcc. But when I type gcc --version I get back

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I may also have some issues with the path. It is currently set to


I added the Applications... path to PATH hoping it would help but it didn't. /usr/bin contains both a g++ and gcc file install May 18, so very recently. I've tried renaming those as a test of whether that would solve the problem but I'm unable to do that even as sudo.

Suggestions greatly appreciated!

  • Use clang not gcc for macos. If an exam plye says gcc then it probably for Linux
    – mmmmmm
    Jun 17, 2020 at 20:02
  • Since seems you have llvm installed, also brew is installed. With this try brew formula R and it will show that "gcc" is required for gfortran - so the simplest way to install R is by using brew install R which will install all required dependences. Brew compiles from sources directly on your computer.
    – Yoan
    Jun 18, 2020 at 12:33

1 Answer 1


For macOS Clang is a more preferred option (Apple stopped shipping gcc with Xcode and replaced it with Clang and the last version of GCC they supported was 4.2.1, it'll overall be more intuitive.). I'd remove GCC and do the following:

Installation of Clang

  1. Run brew update and then brew upgrade in terminal
  2. Run brew install llvm to install LLVM and Clang

To put Clang within your PATH variables:

echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile

I'm not too sure how different the two are when it comes to compiling (although they are probably very similar.) you can proceed with this link to catch up on the commands you'll need to use instead.

  • Use apple's command line version first
    – mmmmmm
    Jun 17, 2020 at 21:19
  • llvm was already installed. Because of directions from on high I have switched to zsh so the bash profile is probably not being use. At least some of the paths are in /etc/paths so I added the llvm path to it. However, the which gcc command still returns /usr/bin/gcc. How/where is this set?
    – JerryN
    Jun 17, 2020 at 22:50
  • Someone downvoted the answer about Clang but didn't say why. Some more explanation would be helpful.
    – JerryN
    Jun 18, 2020 at 13:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .