Apple - Installed gcc with Homebrew, now how to use that gcc instead of clang?

First, examine your $PATH variable.

echo $PATH

The gcc from homebrew should reside in /usr/local/bin and when that is listed before the Xcode version of gcc/clang, you’re done - the local compilers will be called unless a package is hard coded to the full path of a different compiler than the one you have in /usr/local

If you change the PATH variable - be sure to log out of the shell or rehash the shell as appropriate.

This answer has an elegant solution using aliases as well - so you don't even have to think or care about path if you have more than one gcc installed. It goes deeper to let you choose which version of gcc to call if you happen to install more than one version.


you can use gcc-7 instead

reference https://github.com/Homebrew/legacy-homebrew/issues/40374


If which gcc gives you

> which gcc
/usr/bin/gcc

You have two options:

  1. Create an alias.

  2. Make a new gcc symlink under /usr/local/bin/.

    Homebrew links own gcc under /usr/local/bin/gcc-<version> for compatibility. So, doing

    ln -sf /usr/local/bin/gcc-4.9 /usr/local/bin/gcc

will point a /usr/local/bin/gcc symlink to gcc-4.9 installed by Homebrew which should override the gcc from /usr/bin if your PATH specifies /usr/local/bin before /usr/bin.

Tags:

Gcc

Homebrew