I am using CentOS 7.9 and I encountered the same problem after following instructions here to install and run gcc 11. I tried launching different versions of gcc and found only devtoolset-9 works, which corresponds to the file devtoolset-9 in /etc/scl/conf/ folder. So I copied devtoolset-9 to devtoolset-11 in the same folder, and gcc 11 gets working.
I am using CentOS 7.9 and I encountered the same problem after following instructions here to install and run gcc 11. I tried launching different versions of gcc and found only devtoolset-9 works, which corresponds to the file devtoolset-9 in /etc/scl/conf/ folder. So I copied devtoolset-9 to devtoolset-11 in the same folder, and gcc 11 gets working.
I ran into the same issue that you are facing and this is how I got it fixed:
- Just want to be careful, you need to exist the Terminal and open a fresh one to start. This way, you are not under any devtoolset's bash.
- Go to /opt/rh folder, run command ls -la to see if you have any devtoolset-* folder there. Let's say you have devtoolset-8, proceed step 2.
- Go to /etc/scl/prefixes folder, if you don't see devtoolset-8 file, you can create a new one as devtoolset-8, and type 1 line: /opt/rh, then save and quit that file.
- Once you are done, you can call: scl enable devtoolset-8 -- bash w/o any error. Good luck
To install the full tools-set including gfortran on centos 7:
yum install centos-release-scl
yum install devtoolset-8
scl enable devtoolset-8 -- bash
enable the tools:
source /opt/rh/devtoolset-8/enable
you may wish to put the command above in .bash_profile
ref: https://unix.stackexchange.com/questions/477360/centos-7-gcc-8-installation
devtoolset-8 was only released a short while ago. The linked installation instructions may be of use. However, your question pertains to CentOS, and this does not yet appear to have been made available yet. You can see some evidence of it being build for CentOS here, but it's not been updated for the final release yet.
You could ask on the SCL mailing list for an ETA, or wait until it appears in its final form. In the meantime, you could download the RPMs from koji directly.
The version of gcc that's distributed with CentOS 6 is actually 4.4.7.
You can install as many versions of gcc either by installing devtoolset-# via yum or by compiling then from source.
The first way is the easiest. Make sure that you are installing the devtoolset packages via the scl repo. I figure that you already did as you have installed one already but in case you didn't:
yum install centos-release-scl
You can then use the below command to set the gcc version to whichever one you want. Using 5 for this example and assuming that your shell is bash:
scl enable devtoolset-5 bash
If you want to change to 6:
scl enable devtoolset-6 bash
If you want to change back to the default then any of the following will work assuming bash is your shell:
bash
source ~/.bash_profile
The first will start a new shell session and set any aliases/variables/commands in ~/.bashrc. The second will set it with the variables/commands in ~/.bash_profile. (Without the devtoolset enabled).
You can even put scl enable devtoolset-5 bash, for example, in ~/.bashrc or ~/.bash_profile so that it sets the gcc version to one of the devtoolset versions at login. To go back to the system default if you use this method, comment the line out in ~/.bashrc or ~/.bash_profile and then run bash or source ~/.bash_profile, respectively. That will start a new shell session with everything in one of those shell init files except the scl enable command that you commented out. The only downside is that any variables that you've set via the export command will no longer be there as the shell session will be new.
I'm no expert on scl but I do have years of linux experience.
When you do scl enable devtoolset-9 bash what is happening is that a new bash is started and a new environment is set up.
You can see the new bash process by:
- first starting a new shell and checking your shell's pid via
echo $$ - second enabling the new devtoolset via
scl enable devtoolset-9 bash - then check your pid again via
echo $$ - for bonus points you can do
pstree -pto see that your new bash pid has a parent pid of your old bash process
So to finally answer your question: To return to the default g++ compiler all you need to do is exit your current bash process and then you should have the old g++ compiler.
Important note regarding your ~/.bashrc:
- my solution won't work if you have somehow modified your
~/.bashrc - i.e. if you have something in there that always does the
scl enable devtoolset-9 - see the other solutions on this page because the other solutions talk more in-depth about your ~/.bashrc and how to modify or unmodify it
The scl enable ... command creates a new shell; you've probably ended up with several nested layers of shells if you've been testing this. If you exit, you'll probably see the gcc --version output from the base system. See how deeply-nested you are with something like pstree -s $$.
To run gcc --version with scl, just put the command on the scl line:
scl enable devtoolset-9 'gcc --version'
Reference: The Red Hat Developer Toolset 9 User Guide (pdf).
to get the script to act as you want it to, you need the scl command to modify the current bash session rather than spawn a new one.
you can do it this way
#!/usr/bin/env bash
# switch to GCC9 environment for the duration of the script
source scl_source enable devtoolset-9
gcc --version