Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.

share|improve this question
up vote 17 down vote accepted

Most likely it is because bash has gcc hashed.


$ hash

to see which commands are hashed. If /usr/bin/gcc appears on the list, run

$ hash gcc

to rehash gcc. Afterwards you should see /opt/local/bin/gcc if you run hash, and running gcc should run the macports version – providing of course that you have selected it.


Edit: For zsh users, run $ rehash to refresh the hash in its entirety.

share|improve this answer
Well, I did not even know about existence of that mechanism. Thank you! – Mariusz Pluciński Jul 16 '12 at 12:53

I have the same issue, and this is not the correct solution - i'm hoping someone will chime in with one. For the time being, call it directly:

$ gcc-mp-4.7 -v
Using built-in specs.
Target: x86_64-apple-darwin11
    Configured with: ../gcc-4.7.0/configure --prefix=/opt/local --build=x86_64-apple-darwin11 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc47 --includedir=/opt/local/include/gcc47 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.7 --with-libiconv-prefix=/opt/local --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.7 --with-gxx-include-dir=/opt/local/include/gcc47/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --enable-stage1-checking --disable-multilib --enable-lto --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl= --with-pkgversion='MacPorts gcc47 4.7.0_3'
Thread model: posix
gcc version 4.7.0 (MacPorts gcc47 4.7.0_3) 

Hope that helps until a permanent solution is found

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.