Homebrew GCC version select

Homebrew can select GCC versions (and versions of other Homebrew formulae) like:

brew install gcc@15

Then create a file like “~/gcc-15.sh” with the following content:

v=15
prefix=$(brew --prefix gcc@$v)/bin

export CC=$prefix/gcc-$v CXX=$prefix/g++-$v FC=$prefix/gfortran-$v

Activate the GCC version in this shell session by running:

source ~/gcc-15.sh

If there is still trouble, try modifying SDKROOT to find a compatible SDK for the selected Homebrew GCC version.

Using an older version of Homebrew-distributed library or program could be useful to workaround bugs, or if one wants to still use their Intel CPU Mac hardware with Homebrew as GCC 16 isn’t supported by Homebrew on Intel CPUs on macOS for example. The Homebrew bottle binaries or source compile scripts must be available for the CPU architecture and OS version of the computer.