How can I change "which gcc" directory?
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.
Related videos on Youtube
Anton Rasmussen
Computers and Math Guy | Researcher | Data Nerd | Linguist | Student | Drummer | Dad | Human | ... Also, I have an addiction to asking a lot of questions, be they "stupid" or not...
Updated on September 18, 2022Comments
-
Anton Rasmussen over 1 year
gcc-4.8
is installed from build-essential.I used
gcc-4.8
to buildgcc-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
viarm /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 askwhich 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 askwhich gcc
(it actually throwsbash: /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 thegcc
command to compile with my own build (gcc-4.7.4
) instead of the default build?-
steeldriver about 7 years
which
simply checks for executables on yourPATH
- it doesn't follow symlinks AFAIK. If you'd donereadlink -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 yourPATH
. It's not clear what you've done in the meantime to get/usr/bin/gcc: No such file or directory
-
steeldriver about 7 yearsBTW 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
-
2xsaiko about 7 yearsKind of duplicate of askubuntu.com/questions/884576/…, maybe?
-
Anton Rasmussen about 7 yearsAh, 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...)
-
-
Anton Rasmussen about 7 yearsI 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...