Installing and using GCC on Mac Silicon
Published:
*[master][~/repositories/hepcpp/cpluspluscourse/exercises]$ type gcc
gcc is /usr/bin/gcc
*[master][~/repositories/hepcpp/cpluspluscourse/exercises]$ gcc --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
The gcc shipped with Mac Silicon is Apple clang → what?
I want to use the real gcc:
$ brew install gcc
Brew gcc installed in /opt/homebrew/bin/:
$ ls | grep gcc
aarch64-apple-darwin23-gcc-14
aarch64-apple-darwin23-gcc-ar-14
aarch64-apple-darwin23-gcc-nm-14
aarch64-apple-darwin23-gcc-ranlib-14
gcc-14
gcc-ar-14
gcc-nm-14
gcc-ranlib-14
$ ./gcc-14 --version
gcc-14 (Homebrew GCC 14.2.0_1) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Now to use the brew installed gcc, I simply need to add installation directory to PATH:
*[master][~/repositories/hepcpp/cpluspluscourse/exercises]$ echo $PATH | grep bin
... :/opt/homebrew/bin:/opt/homebrew/sbin: ... :/usr/bin:/bin:/usr/sbin ...
Both the shipped and brew installed gccs are on PATH…
$ type gcc
gcc is /usr/bin/gcc
aaaand the shipped gcc is still being used.
I can either:
- alias; or
- create new gcc symlink → need to have PATH specify /usr/local/bin before /usr/bin
References: https://stackoverflow.com/questions/64992467/mac-clang-installation-seems-to-override-gcc-install
https://apple.stackexchange.com/questions/245891/installed-gcc-with-homebrew-now-how-to-use-that-gcc-instead-of-clang
