The current version of GCC on my mac is 9.3.0, and the latest version is 10.2 now. I want to update GCC to the latest version via Homebrew. How can I do that?
The standard command
brew upgrade gcc should work. The formula for
gcc points to the latest version. You can also install a specific version, ex.
brew install gcc@10.
I did this, but after upgrading when I checked the gcc version (using gcc --version), it shows me the Clang version. What’s the problem?
If you installed Xcode and/or the Command Line Tools, it ships with its own
~$ xcode-select -p /Library/Developer/CommandLineTools ~$ /Library/Developer/CommandLineTools/usr/bin/gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple clang version 12.0.0 (clang-122.214.171.124) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
That's the same output as
~$ which gcc /usr/bin/gcc ~$ gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1 Apple clang version 12.0.0 (clang-1126.96.36.199) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
As with most Homebrew installations, Homebrew's
gcc is in the Cellar:
~$ ls /usr/local/Cellar/gcc/10.2.0_1/bin | grep gcc gcc-10 gcc-ar-10 gcc-nm-10 gcc-ranlib-10 x86_64-apple-darwin19-gcc-10 x86_64-apple-darwin19-gcc-10.2.0 x86_64-apple-darwin19-gcc-ar-10 x86_64-apple-darwin19-gcc-nm-10 x86_64-apple-darwin19-gcc-ranlib-10 ~$ /usr/local/Cellar/gcc/10.2.0_1/bin/gcc-10 --version gcc-10 (Homebrew GCC 10.2.0_1) 10.2.0 Copyright (C) 2020 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.