This has been plaguing me for awhile now. I am trying to compile a huge C++ file (I know it works as I it works fine on my Arch Linux computer at work). When I checked my GCC version on my mac It returns the following
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.1.0 Thread model: posix
I have also installed the most recent GCC version using Homebrew with
brew install gcc49
My question now is how do I apply that newly installed GCC version to be the default version that the terminal uses?
I am also aware that when you use homebrew to isntall gcc it names it gcc-49 so that there is no confusion between packages.
I have no idea how to replace the 4.2.1 version that comes with XCode with the 4.9 version I have installed.
Thanks
Edit: Switched to my mac to get the full return statement of gcc --version
Edit 2: My end game here is to be able to navigate to the directory and be able to type
make sudo make install
to install the daemon that has been made. Right now that returns tons of errors with random packages and the Standard Library
Go back to the terminal type cd /usr/local/bin . From here run an ls and identify the latest version of GCC and G++ that you would like to symlink against. For me, that is currently gcc-11 and g++-11 .
Mixing Xcode and osx-gcc-installer is known to cause various difficult-to-diagnose problems and is not recommended. Thus, we need to uninstall Xcode and the osx-gcc-installer: Run /Library/Developer/4.1/uninstall-devtools -mode=all. Uninstall Xcode.
By default, homebrew
places the executables (binaries) for the packages it installs into /usr/local/bin
- which is a pretty sensible place for binaries installed by local users when you think about it - compared to /bin
which houses standardisded binaries belonging to the core OS. So, your brew
command should have installed gcc-4.9
into /usr/local/bin
. The question is now how to use it... you have several options.
Option 1
If you just want to compile one or two things today and tomorrow, and then probably not use the compiler again, you may as well just invoke the gcc
installed by homebrew
with the full path like this:
/usr/local/bin/gcc-4.9 --version
Option 2
If you are going to be using gcc
quite a lot, it gets a bit tiresome explicitly typing the full path every time, so you could put the following into your ~/.bash_profile
export PATH=/usr/local/bin:$PATH
and then start a new Terminal and it will know it needs to look in /usr/local/bin
, so you will be able to get away with simply typing
gcc-4.9 --version
Option 3
If you just want to use gcc
to invoke the compiler, without worrying about the actual version, you can do Option 2 above and additionally create a symbolic link like this
cd /usr/local/bin ln -s gcc-4.9 gcc
That will allow you to run the homebrew
-installed gcc
by simply typing gcc
at the command line, like this
gcc --version
Note:
If you later want to install, say gcc-4.13
or somesuch, you would do your brew install
as before, then change the symbolic link like this:
cd /usr/local/bin rm gcc # remove old link from gcc to gcc-4.9 ln -s gcc-4.13 gcc # make new link from gcc to gcc-4.13
Note that if you are actually using C++
rather than C
, you will need to adapt the above for g++
in place of gcc
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With