I installed gcc with brew install gcc, but when I type gcc the default behavior is still to use clang. How do I set things so that typing gcc in the terminal automatically uses the gcc installed by Homebrew?


You probably will want to examine your $PATH variable. The gcc from homebrew should reside in /usr/local/bin and that should be before the Xcode version of gcc/clang.

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.

  • Putting the homebrew gcc earlier in the $PATH variable than the Xcode version is sufficient to guarantee that the homebrew gcc will be referenced? I wasn't sure how double definitions in $PATH would work. – NeutronStar Jul 13 '16 at 23:58
  • 2
    Paths are order dependent. Putting /usr/local ahead of /usr is a standard way to override the default application. I've seen people put a ~/bin ahead of that. – Andrew Lazarus Jul 14 '16 at 21:04
  • Homebrew does not put gcc in /usr/local/bin. This is for compatibility as everything would then use gcc instead of the system clang compiler (which is also aliased as gcc). What it does do is put a versioned link in /usr/local/bin such as gcc-8. – Jason May 9 '19 at 21:27

you can use gcc-7 instead

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

You must log in to answer this question.

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