I have two version of GCC on the same linux system. How do i make the latest GCC version as default C++ compiler?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have two version of GCC on the same linux system. How do i make the latest GCC version as default C++ compiler?
Please do just say uninstall old version, without hints on how to remove carefully or hurting other dependencies!
I have installed GCC-8.2.0 on my machine and added it to the $PATH. I did the installation as super user (SU). By default my system has an older version gcc-4.7 already installed.
After installation,when I give the command 'gcc --version' in the default terminal (not as super user) the outcome is:
gcc (GCC) 4.7.0
however if i give 'gcc --version' from the Super User mode, it gives:
gcc (GCC) 8.2.0.
(Please note: i installed the GCC in the SU mode. And /gcc-8.2.0/bin was added to PATH in SU mode)
Seems like unless i am in SU mode, my default compiler is GCC-4.7.0
I would like to use the gcc-8.2.0 as default. Also, if gcc-8.2.0 works, how do i remove gcc-4.7 without breaking the system( someone advised me to uninstall gcc-4.7 first, but that didn't work since gcc-8.2.0 cannot be compiled without a c/c++ compiler). i used 'yum install gcc' to install gcc-4.7.
My system configuration:
Operating system: CENTOS6
yes! you're right. i am trying to use c++ compiler by installing the gcc-8.2. Now, I am able to use the gcc-8.2 but only in the SU mode. would it be possible to make gcc-8.2 accessible to other users too. My goal is to shift to gcc-8.2, if that's possible.
did you add gcc-8.2 to the path for regular users? are the files in gcc-8.2 executable by regular users?
the gcc-8.2 file/directories (like bin,lib etc) are kept in /home/biopo/gcc-8.2/ and i have added /home/biopo/gcc-8.2/bin to the path by writing the .bashrc file. All this were done in the SU mode. Seems like i cannot access this as non-SU users. what have i done (possibly) that made it inaccessible to the other users?? I performed configure,make,make install in SU mode.
Sorry for the dummy questions. Have been consumed by this installation for a week now only beacause i want to install gromacs. And gromacs needs openbabel. openbabel needs cmake,eigen,qt etc. And cmake,openbable needs gcc etc. I am a late bloomer in linux.
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304
Rep:
the configuration files for normal users will be in /etc. maybe /etc/profile. you would need to make changes there, or edit the .bashrc in each users home directory. you can check the path settings for a user by logging in as that user and running
Code:
set
. you can check the permissions of the files in a directory by using
Code:
ls -l
also, any libraries that the system will use should be included in /etc/ld.so.conf. you may wish to add that new gcc library path. if you place your new gcc library path at the first of that file, you can be sure that the new libraries are used instead of the old ones.
the configuration files for normal users will be in /etc. maybe /etc/profile. you would need to make changes there, or edit the .bashrc in each users home directory. you can check the path settings for a user by logging in as that user and running
Code:
set
. you can check the permissions of the files in a directory by using
Code:
ls -l
also, any libraries that the system will use should be included in /etc/ld.so.conf. you may wish to add that new gcc library path. if you place your new gcc library path at the first of that file, you can be sure that the new libraries are used instead of the old ones.
I have looked at the file/dir permission. The results of which, whereis, --version are saying that gcc-8.2 is in /root/keretsu/GCC-8.2.0. however, i cannot find the GCC-8.2.0 inside keretsu.
[keretsu@biopo5 GCC-8.2.0]# which gcc
/root/keretsu/GCC-8.2.0/bin/gcc
[keretsu@biopo5 GCC-8.2.0]# gcc --version
gcc (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[keretsu@biopo5 GCC-8.2.0]# ls -l
total 24
drwxr-xr-x 2 root root 4096 Aug 1 16:27 bin
drwxr-xr-x 3 root root 4096 Aug 1 16:26 include
drwxr-xr-x 3 root root 4096 Aug 1 16:26 lib
drwxr-xr-x 3 root root 4096 Aug 1 16:27 lib64
drwxr-xr-x 3 root root 4096 Aug 1 16:26 libexec
drwxr-xr-x 6 root root 4096 Aug 1 16:27 share
Now if go to root and give 'ls' command there is no directiory with name 'keretsu'. Instead, if i go to 'home' from 'root' and open keretsu (i.e root>home>keretsu), there is still no directory "GCC-8.2.0"
Here is the content of root direcotry:
[keretsu@biopo5 /]# ls -a
. bin dev lib misc proc sbin tmp
.. boot etc lib64 mnt .pulse selinux usr
.autofsck cgroup home lost+found net .pulse-cookie srv var
.autorelabel .dbus include media opt root sys
There is no "keretsu" directory.
what am i missing ? i don't understand how GCC-8.2 is not visible to me even as the SU.
Please note: when i installed gcc-8.2.0, during the configuration i gave "$PWD/../gcc-4.6.2/configure --prefix=$HOME/GCC-4.6.2 --enable-languages=c,c++,fortran,go"
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304
Rep:
i was hoping you would
Code:
ls -l /root/keretsu/GCC-8.2.0/bin/
and the path settings for users is the file /etc/profile
Code:
ls -al
will show all files including hidden ones.
i think you are confusing the root /, with the root directory /root. i know it can be confusing. the su is also the root user. the root user's home directory is /root. so when you became su, your home directory was /root, so when you installed your new gcc in --prefix=$HOME/GCC-4.6.2? wait.. was that a typo? i don't know, but as su, the value of $HOME is /root/.
A few things, why are you setting --prefix in your configure command? The sets the base install path. It defaults to /usr/local/ which would be accessible to all users on the system. Setting it to something in /root is going to make it inaccessible to non-privileged users. Unless you chmod 755 /root. But still, that's not a typical place you would install executables for all users.
If you install to a path that is not already in the default $PATH evironment variable then you'll have to add it to $PATH in your startup script, "~/.bash_profile", if you're using bash. You'll want to add the path to the new gcc to front of the string in $PATH to pick it up before the old one.
You can also set an alias in there for whatever user you're wanting to use the new gcc install, "alias gcc='$NEW/$PATH/$TO/$BIN'". Just make sure wherever your new gcc is that the permissions are set so that your user can see and run it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.