Change GCC Version to 4.7 on Mac OS X

g++, gcc, macos

Solution

Tricky question if we don’t know the full path of the other installs. But basically you could change the $PATH order in your local user `.profile` settings. So let’s say your 4.7 install is in `/usr/local/bin/` & we know the Apple default version is in `/usr/bin/` then edit your `.profile` so `/usr/local/bin/` comes before `/usr/bin/` in $PATH order.

Default should be something like this:

export PATH=/usr/bin:/usr/local/bin:[etc, etc, etc]

Adjusted should be something like this:

export PATH=/usr/local/bin:/usr/bin:[etc, etc, etc]

There is a way to force this change systemwide for all users, but I do not recommend that. Don’t muck around with the deeper—and often non-standard—ways Apple implements a *nix environment. Keep it local to your user.

EDIT: Check the discussion here to see if any solutions offered can help you. It does seem like installing `gcc_select` via MacPorts would be the cleanest solution.

Problem

On OS X, I currently have a couple versions of gcc installed. Whenever I use `gcc -v` or `g++ -v`, it tells me: `gcc version 4.2.1`. I have installed gcc 4.7, though, in the interest of taking advantage of C++11. How can I change it so that gcc/g++ points to 4.7 instead of 4.2.1? EDIT: I have homebrew, not macports.

Original source

Related problems