I am working on OS X 10.7 (Lion). I have installed gcc 4.7 from macports:
sudo port install gcc47
It seems to be working properly:
$ /opt/local/bin/gcc-mp-4.7 -v
(...)
gcc version 4.7.0 (GCC)
Now, I am trying to change default compiler by using port select:
$ sudo port select gcc mp-gcc47
Selecting 'mp-gcc47' for 'gcc' succeeded. 'mp-gcc47' is now active.
It copies gcc binary to /opt/local/bin/gcc, which works properly:
$ /opt/local/bin/gcc -v
(...)
gcc version 4.7.0 (GCC)
It also changes default gcc:
$ which gcc
/opt/local/bin/gcc
But running this default one does not work:
$ gcc -v
gcc-mp-4.7: error trying to exec '/opt/local/bin/i686-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory
This binary "i686-apple-darwin11-llvm-gcc-4.2" is the original Apple's provided gcc version; I don't know why it tries to look on it in /opt/local/bin, or even why it tries to run it at all. If I create symlink, it simply calls this binary, which is not what I want:
$ sudo ln -s /usr/bin/i686-apple-darwin11-llvm-gcc-4.2 /opt/local/bin
$ gcc -v
(...)
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
How to solve it, to make gcc working properly, by simply calling "gcc"? As far as I know, there was gcc_select tool in older OS X, but my system does not have it.
Best Answer
Most likely it is because bash has
gcc
hashed.Run
to see which commands are hashed. If /usr/bin/gcc appears on the list, run
to rehash
gcc
. Afterwards you should see /opt/local/bin/gcc if you runhash
, and runninggcc
should run the macports version – providing of course that you have selected it./B2S
Edit: For zsh users, run
$ rehash
to refresh the hash in its entirety.