2

I installed gcc with homebrew:

$ brew install gcc

I can see the result:

$ brew list
ant         gcc     go          libyaml     postgresql  tmux
autoconf    gdb     isl         mpfr        python      valgrind
automake    gdbm    libevent    openssl     readline    wget
binutils    git     libmpc      ossp-uuid   ruby        xz
cloog       gmp     libtool     pkg-config  sqlite

I also see gcc-4.9 in /usr/local/bin

$ ls /usr/local/bin
...
gcc-4.9
...

The issue is that typing gcc still refers to the system gcc

$ which gcc
/usr/bin/gcc

I wanted to rename gcc-4.9 to gcc, but I don't want to break anything in homebrew. Specifically, I'd like to rename it in such a way that homebrew is aware of the change and running brew update will know to link the newly updated version to the name gcc in /usr/local/bin.

Can this be done?

DESIRED BEHAVIOR:

$ which gcc
/usr/local/bin/gcc
$ gcc -v
... version XXX
$ brew update
... new gcc version YYY installed in /usr/local/bin/gcc
$ which gcc
/usr/local/bin/gcc
$ gcc -v
... version YYY
  • You can rename /usr/bin/gcc to something else and create gcc symlink to /usr/local/bin/gcc-4.9. – Mateusz Szlosek Oct 30 '14 at 10:08
  • I usually just put an alias in my .bash_profile that refers to the one I want. Hackish way of doing it, but it works. – aglasser Oct 31 '14 at 21:13
3

I don't think what you want can be done directly without hacking Homebrew formulas, er, I mean formulae.

What I do is put

export CC=gcc-4.9

in my shell profile. That works in almost all scenarios I'm interested in.

An alternative is that you create your own "bin" directory, say ~/bin/, put that first in the path, and symlink ~/bin/gcc to /usr/local/bin/gcc-4.9.

Both of these methods will survive package upgrades.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .