gcc-4.8 is installed from build-essential.

I used gcc-4.8 to build gcc-4.7.4 from source, and put that 4.7 build in a folder called /AntonProj1

I have been able to change the symbolic link from the default gcc to the build in /AntonProj1 via

rm /usr/bin/gcc

ln -s /AntonProj1/bin/gcc /usr/bin/gcc

So, while I can find the correct version (4.7.4) by doing gcc-v, I am still linked to /usr/bin/gcc when I ask which gcc

When I try something like:

ln -s /AntonProj1/bin/gcc /AntonProj1/tmp/gcc

I am no longer able to get the correct version doing -v and it is still looking in /usr/bin/gcc when I ask which gcc (it actually throws bash: /usr/bin/gcc: No such file or directory)

How can I build a link to, for example, /AntonProj1/tmp/gcc so that I can use the gcc command to compile with my own build (gcc-4.7.4) instead of the default build?

  • which simply checks for executables on your PATH - it doesn't follow symlinks AFAIK. If you'd done readlink -f $(which gcc) you should have arrived at /AntonProj1/bin/gcc. However IMHO it would be cleaner to simply add /AntonProj/bin to the front of your PATH. It's not clear what you've done in the meantime to get /usr/bin/gcc: No such file or directory Mar 30, 2017 at 18:43
  • 1
    BTW why did you install gcc-4.7.4 from source at all? it seems to be available in the repositories up until at least Ubuntu 16.10 Mar 30, 2017 at 18:45
  • Kind of duplicate of askubuntu.com/questions/884576/…, maybe?
    – 2xsaiko
    Mar 30, 2017 at 18:46
  • Ah, ok. I will check the PATH settings. Thanks! (And I installed it from source for a personal challenge. I'm trying to build 40 or so projects from source; but, I wanted to build gcc from source first so I could use that compiler to build the others...) Mar 30, 2017 at 18:48

1 Answer 1


This is what I did to fix things the way I was looking for them to be when I asked the question. I'm not sure if this is the best way; but, it's working for now:

Setting up symbolic links:

Remove existing links:

rm /usr/bin/gcc
rm /usr/bin/g++

Change name of default executibles because I want to run commands gcc and g++:

mv /AntonProj1/bin/gcc /AntonProj1/bin/gcc-4.7.4
mv /AntonProj1/bin/g++ /AntonProj1/bin/g++-4.7.4

Set new symbolic links:

ln -s /AntonProj1/bin/gcc-4.7.4 /AntonProj1/bin/gcc
ls -s /AntonProj1/bin/g++-4.7.5 /AntonProj1/bin/g++

Setting up PATH stuff:

export "PATH+=:/AntonProj1/bin"

While I'm not sure my method of setting up the path is ideal (it must not be since I have to add a path to any directory I'd like to run gcc or g++ from), this easy export appends the correct path to the end of whatever path is already set... I can imagine setting it up in a profile.d or something; but, for my purposes it's OK as it is.

  • I discovered the way to do this permanently by setting the PATH by putting the export in the .profile file of the home directory: export "PATH=/AntonProj1/bin:/AntonProj1/share:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" Of note here is that the new path should be at the beginning and not at the end... Apr 6, 2017 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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