0

I had installed gcc on Mac High Sierra(as its needed for some software that I need to use). I was asked to check if my gcc was updated, in order to install the said software. Upon some searching, I found this command to find it -

gcc -dumpversion | cut -f1,2,3 -d.

This gives the output as 4.2.1.

When I try to run brew install gcc, it however says -

Error: gcc 8.2.0 is already installed To upgrade to 8.3.0, run brew upgrade gcc

I don't understand why these two commands give different versions of gcc installed, and which of the two could actually be getting used while I am trying to install the software. Any help would be appreciated!

1 Answer 1

1

PATH!

The first is running /usr/bin/gcc from XCode which gives a GCC 4.2.1 version. The second is running the version from where brew installs it. You need to fix your PATH so that the Brew (HomeBrew) bin directory is on your PATH before /usr/bin. I think that's /usr/local/bin, but you may have a different location. (I tend to install things in oddball locations; referring to /usr/local/Homebrew/bin and /usr/local/Cellar may not help you.)

Wherever it is installed, make sure that the directory is on your PATH before the /usr/bin directory. That may involve hacking your ~/.profile file, or ~/.bashrc – again, depending on how you set things up. If you use tcsh, it'll be ~/.login or ~/.cshrc that needs editing.

You may also find /usr/libexec/path_helper helpful; look at the manual page for it (man path_helper) to see how to modify its default configuration. Be careful how you do that, and make backups, and test (bash -l to simulate a login).

Sign up to request clarification or add additional context in comments.

8 Comments

Hi Jonathan, I did change my .bash_profile to include export PATH="/usr/local/bin:$PATH" export PATH="/usr/bin:$PATH", and activated the changes, but on running gcc -dumpversion | cut -f1,2,3 -d., it still gives me 4.2.1 and on running which gcc, it still gives me /usr/bin/gcc. Any ideas what could be going wrong? I did try all this on a new instance of the terminal
Maybe hash -r? Maybe run the two variants by full pathname to see that they do report different versions.
I also tried adding alias gcc='/usr/local/bin/gcc-8' to the .bash_profile, but that didn't work either. I am a bit hesistant about hash -r since it would make it forget ALL remembered locations, but I will do it if there's no other option. Didn't quite understand what you meant by your second statement
I have precisely one alias in my profile and an essentially empty bashrc. I don’t like the confusion that aliases cause. If I need it, it’s a script. I have hundreds of them. Literally! (My private bin directory has over 500 programs and scripts in it.) if you can’t get the path to work, make symlinks gcc-4 to /usr/bin/gcc and gcc-8 to /usr/local/bin/gcc and use the suffixed names. Or something along those lines.
If you're still having problems, it's going to take a good deal of data to work out what's going wrong — lists of files in directories (at least, of files with a name that matches gcc*), and environment, and making sure the modified PATH is exported properly, and so on. The most relevant directories are /usr/bin and /usr/local/bin. It'll turn out to be something small and silly and obvious once spotted (but mystifying until spotted). If you're really stuck, contact me by email — see my profile. Please include a link to this question to identify what the subject is about.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.