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.

Answer from zzzhhh on Stack Overflow
Top answer
1 of 4
7

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.

2 of 4
1

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 -p to 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
🌐
Princeton CS Guide
csguide.cs.princeton.edu › software › gcc
GCC, the GNU Compiler Collection | Department of Computer Science Computing Guide
All cycle servers have DevToolSet installed and gcc versions 4.9.2 and 5.3.1 are available. Version 4.8.5 is the default gcc version.
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_developer_toolset › 11 › html › user_guide › chap-gcc
Chapter 2. GNU Compiler Collection (GCC) | User Guide | Red Hat Developer Toolset | 11 | Red Hat Documentation
Red Hat Developer Toolset is distributed with GCC 11.2. This version is more recent than the version included in Red Hat Enterprise Linux and provides a number of bug fixes and enhancements. In Red Hat Developer Toolset, the GNU C compiler is provided by the devtoolset-11-gcc package and is ...
🌐
Red Hat
access.redhat.com › documentation › en-us › red_hat_developer_toolset › 12 › html-single › user_guide › index
User Guide | Red Hat Developer Toolset | 12 | Red Hat Documentation
May 9, 2023 - Red Hat Developer Toolset is distributed with GCC 12.2.1. This version is more recent than the version included in Red Hat Enterprise Linux and provides a number of bug fixes and enhancements. In Red Hat Developer Toolset, the GNU C compiler is provided by the devtoolset-12-gcc package and ...
🌐
Softwarecollections
softwarecollections.org › en › scls › rhscl › devtoolset-8
Developer Toolset 8 — Software Collections
# 1. Install a package with repository for your system: # On CentOS, install package centos-release-scl available in CentOS repository: $ sudo yum install centos-release-scl # On RHEL, enable RHSCL repository for you system: $ sudo yum-config-manager --enable rhel-server-rhscl-7-rpms # 2. Install the collection: $ sudo yum install devtoolset-8 # 3. Start using software collections: $ scl enable devtoolset-8 bash · At this point you should be able to use gcc and other tools just as a normal application.
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_developer_toolset › 10 › html-single › user_guide › index
User Guide | Red Hat Developer Toolset | 10 | Red Hat Documentation
Red Hat Developer Toolset is distributed with GCC 10.2.1. This version is more recent than the version included in Red Hat Enterprise Linux and provides a number of bug fixes and enhancements. In Red Hat Developer Toolset, the GNU C compiler is provided by the devtoolset-10-gcc package and is automatically installed with devtoolset-10-toolchain as described in Section 1.5, “Installing Red Hat Developer Toolset”.
Find elsewhere
🌐
Red Hat
access.redhat.com › documentation › en-us › red_hat_developer_toolset › 10 › html › user_guide › chap-gcc
Chapter 2. GNU Compiler Collection (GCC) | User Guide | Red Hat Developer Toolset | 10 | Red Hat Documentation
March 28, 2022 - Red Hat Developer Toolset is distributed with GCC 10.2.1. This version is more recent than the version included in Red Hat Enterprise Linux and provides a number of bug fixes and enhancements. In Red Hat Developer Toolset, the GNU C compiler is provided by the devtoolset-10-gcc package and is automatically installed with devtoolset-10-toolchain as described in Section 1.5, “Installing Red Hat Developer Toolset”.
🌐
Upenn
hpcwiki.pmacs.upenn.edu › index.php › HPC:Developer_Tool_Set
HPC:Developer Tool Set - HPC wiki
devtoolset-2 is a set of packages that includes newer versions of gcc, gdb, and other standard libraries.
🌐
Red Hat
access.redhat.com › documentation › en-us › red_hat_developer_toolset › 11 › html-single › user_guide › index
User Guide | Red Hat Developer Toolset | 11 | Red Hat Documentation
July 19, 2023 - Red Hat Developer Toolset is distributed with GCC 11.2. This version is more recent than the version included in Red Hat Enterprise Linux and provides a number of bug fixes and enhancements. In Red Hat Developer Toolset, the GNU C compiler is provided by the devtoolset-11-gcc package and is ...
🌐
Ahelpme
ahelpme.com › home › linux › centos 7 › how to install new gcc and development tools under centos 7
How to install new gcc and development tools under CentOS 7 | Any IT here? Help Me!
September 5, 2019 - And you’ll be in a bash environment, which is configured for GNU GCC 7. [srv@local ~]# scl enable devtoolset-7 bash [srv@local ~]# which gcc /opt/rh/devtoolset-7/root/usr/bin/gcc [srv@local ~]# gcc --version gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5) Copyright (C) 2017 Free Software Foundation, ...
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_developer_toolset › 9 › html › 9.0_release_notes › dts9.0_release
Chapter 2. Red Hat Developer Toolset 9.0 Release | 9.0 Release Notes | Red Hat Developer Toolset | 9 | Red Hat Documentation
All components in Red Hat Developer Toolset 9.0 are distributed as new packages with the devtoolset-9- prefix and only for Red Hat Enterprise Linux 7. The following components have been upgraded in Red Hat Developer Toolset 9.0 compared to the previous release of Red Hat Developer Toolset: ... In addition, Red Hat Developer Toolset 9.0 introduces a new component, Annobin, a build security checking tool. The tool consists of annobin, a plug-in for GCC, and annocheck, a program for examining compiled binary files.
🌐
Linux @ CERN
linux.web.cern.ch › devtoolset
Developer Toolset - Linux @ CERN
$ scl enable devtoolset-1.1 bash $ gcc --version gcc (GCC) 4.7.2 20121015 (Red Hat 4.7.2-5) Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions.