LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 08-01-2018, 04:12 AM   #1
seke
LQ Newbie
 
Registered: Jul 2018
Location: south korea
Distribution: centos
Posts: 9

Rep: Reputation: Disabled
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

Kindly advise. Thank you.
 
Old 08-01-2018, 07:38 AM   #2
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
It sounds like you only installed GCC 8.2.0 for the root user and not for all users.

Is this about the same problem as your other thread ?
 
Old 08-01-2018, 09:44 PM   #3
seke
LQ Newbie
 
Registered: Jul 2018
Location: south korea
Distribution: centos
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jsbjsb001 View Post
It sounds like you only installed GCC 8.2.0 for the root user and not for all users.

Is this about the same problem as your other thread ?
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.

Thanks
 
Old 08-01-2018, 09:49 PM   #4
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
did you add gcc-8.2 to the path for regular users? are the files in gcc-8.2 executable by regular users?
 
Old 08-01-2018, 10:03 PM   #5
seke
LQ Newbie
 
Registered: Jul 2018
Location: south korea
Distribution: centos
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by whansard View Post
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.

will appreciate your help.
 
Old 08-01-2018, 10:46 PM   #6
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
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.

Last edited by whansard; 08-01-2018 at 10:51 PM.
 
Old 08-02-2018, 02:48 AM   #7
seke
LQ Newbie
 
Registered: Jul 2018
Location: south korea
Distribution: centos
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by whansard View Post
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]# whereis gcc
gcc: /usr/share/man/man1/gcc.1.gz

[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

[keretsu@biopo5 GCC-8.2.0]# pwd
/root/keretsu/GCC-8.2.0

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"
 
Old 08-02-2018, 11:36 PM   #8
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
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/.

Last edited by whansard; 08-02-2018 at 11:43 PM.
 
Old 08-03-2018, 02:00 AM   #9
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
i didn't want to just do it for you, but
Code:
chmod 755 /root/keretsu/GCC-8.2.0/bin/*
cp /etc/profile /etc/profile.backup
echo "export PATH=/root/keretsu/GCC-8.2.0/bin:$PATH" >> /etc/profile
use at your own risk. i could have easily messed up.
 
Old 08-06-2018, 09:46 PM   #10
Deviathan
Member
 
Registered: Dec 2005
Posts: 52

Rep: Reputation: 18
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.

Last edited by Deviathan; 08-06-2018 at 09:48 PM.
 
  


Reply

Tags
centos, gcc, installation, path



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] The latest gcc/g++ version we can find on a linux distribution is 4.6.3 ? esgol Linux - Newbie 7 07-10-2012 07:14 AM
How to install an older version of gcc compiler teki Linux - Newbie 7 07-10-2010 09:50 AM
making old version of GCC your default compiler knobby67 Programming 4 08-01-2006 04:21 PM
How to change the gcc compiler's default version? aladin Linux - Software 8 10-09-2005 08:07 PM
unable to install latest gcc version sapadman Linux - Newbie 1 07-20-2004 05:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration