How to Set GCC as Default Compiler (Homebrew on macOS)
1. Check Current Compiler
gcc --versionThis will give output like:
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
2. Install GCC Using Homebrew
- Run:
brew install gcc- It will be installed somewhere like
/opt/homebrew/Cellar/gcc/15.1.0/. - Go to the
bindirectory and check the GCC version:
gcc-15 --versionThis should point to the Homebrew version.
3. Set Homebrew GCC as Default
- Go to the Homebrew
bindirectory:
cd /opt/homebrew/bin- Create symbolic links:
ln -s gcc-15 gcc
ln -s g++-15 g++4. Verify Default GCC/G++
- Check where the default
gccorg++is pointing to:
where gccExample output:
/opt/homebrew/bin/gcc
/usr/bin/gcc