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
🌐
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.
Discussions

In centos,how to switch to default gcc after switched to a higher version of gcc with devtoolset - Unix & Linux Stack Exchange
I want to install several gcc with different versions in centos. The default version of gcc in centos 6 is 4.9.3. So I use devtoolset install a higher version of gcc. Then I switch to the higher v... More on unix.stackexchange.com
🌐 unix.stackexchange.com
December 1, 2018
gcc - Updating GLIBCXX with devtoolset-10 - Stack Overflow
We use devtoolset-10 in CentOS 7 ("Actual" default version of gcc in OS is 4.8.5, but in devtoolset we use 10.2.1 version, which is real actual version for project). Command gcc --version More on stackoverflow.com
🌐 stackoverflow.com
Installing gcc versions on Centos7 / Redhat7 - Programming - Linux Tips
You can install these newer versions ... Now you can install gcc-6.x, gcc-7.x etc. with proper parameter like below: sudo yum install devtoolset-6-gcc* This method brings newer versions without uninstalling or ov...... More on linux-tips.com
🌐 linux-tips.com
0
September 20, 2018
Devtoolset is a game changer for C++ development on Linux

what is devtoolset ?

More on reddit.com
🌐 r/cpp
31
20
March 23, 2018
🌐
Stanford
confluence.slac.stanford.edu › display › SCSPub › Red+Hat+Software+Collections
Red Hat Software Collections - Scientific Computing Services Public - SLAC Confluence
July 5, 2024 - The current RPM names (versions subject to change) for the versions of gcc are: ksa@rhel6-64l $ rpm -q devtoolset-6 devtoolset-6-6.1-1.el6.x86_64
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
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_developer_toolset › 9 › html › user_guide › chap-gcc
Chapter 2. GNU Compiler Collection (GCC) | User Guide | Red Hat Developer Toolset | 9 | Red Hat Documentation
Red Hat Developer Toolset is distributed with GCC 9.3.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-9-gcc package and is ...
🌐
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: ...
🌐
Red Hat
developers.redhat.com › blog › 2019 › 06 › 20 › developer-toolset-8-1-and-gcc-8-3-now-available-for-red-hat-enterprise-linux-7
Developer Toolset 8.1 and GCC 8.3 now available for Red Hat Enterprise Linux 7 | Red Hat Developer
March 28, 2023 - GCC 8.3.1 · GDB 8.2 · binutils 2.30 · elfutils 0.176 · Valgrind 3.14.0 · Package name: devtoolset-8 · Container image: rhscl/devtoolset-8-toolchain-rhel7; rhscl/devtoolset-8-perftools-rhel7 · System support: RHEL 7 for x86_64, IBM Z, ...
Find elsewhere
🌐
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 ...
🌐
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.
🌐
Upenn
hpcwiki.pmacs.upenn.edu › index.php › HPC:Developer_Tool_Set
HPC:Developer Tool Set - HPC wiki
devtoolset-2-gcc-4.8.0-5 devtoolset-2-libstdc++-devel-4.8.0-5 devtoolset-2-runtime-2.0-14 devtoolset-2-gdb-7.6-28 devtoolset-2-libquadmath-devel-4.8.0-5 devtoolset-2-gcc-gfortran-4.8.0-5 devtoolset-2-gcc-c++-4.8.0-5 devtoolset-2-binutils-2.23.52.0.1-5
🌐
Red Hat
access.redhat.com › solutions › 19458
What GCC versions are available in Red Hat Enterprise Linux? - Red Hat Customer Portal
July 21, 2025 - What GCC versions are available in Red Hat Enterprise Linux? What C and C++ compiler comes with RHEL, GCC Toolset, Developer Toolset? Are the GCC Toolset and Developer Toolset available for my RHEL version?
🌐
Red Hat
developers.redhat.com › articles › 2025 › 04 › 16 › gcc-and-gcc-toolset-versions-rhel-explainer
GCC and gcc-toolset versions in RHEL: An explainer | Red Hat Developer
April 16, 2025 - This compiler receives full support for the entire life cycle of the major version of RHEL: ... Even though the upstream GCC project might no longer support these versions (such as GCC 8), Red Hat takes responsibility for maintaining them throughout RHEL’s life cycle.
🌐
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 ...
🌐
Linux Tips
linux-tips.com › programming
Installing gcc versions on Centos7 / Redhat7 - Programming - Linux Tips
September 20, 2018 - Centos7 and Redhat7 still uses too old gcc 4.8.5 version and this becomes very annoying if you want to use newer features in your C/C++ programs. You can install these newer versions with Devtoolset-4 from the Software Collections project. First of all enable software collections repo: sudo yum install centos-release-scl Now you can install gcc-6.x, gcc-7.x etc. with proper parameter like below: sudo yum install devtoolset-6-gcc* This method brings newer versions without uninstalling or ov...
🌐
Reddit
reddit.com › r/cpp › devtoolset is a game changer for c++ development on linux
r/cpp on Reddit: Devtoolset is a game changer for C++ development on Linux
March 23, 2018 -

On Linux the dependency on system compilers have always been frustrating since it means your stuck with ancient GCC versions. But I must say I'm very impressed with devtoolset for RHEL/CentOS, it means you can use gcc-7 on old crappy RHEL6 that so many large companies insist on using. And you can ship the resulting binaries and it will run on plain vanilla RHEL installations!

Top answer
1 of 5
12

what is devtoolset ?

2 of 5
6

devtoolset-7 also provides newer versions of lots of supporting debug and performance tools like gdb.

They (RH or Centos) also provide containerised versions of the build tools and the performance tools.

There is also a tech preview of the llvm-toolset, admittedly at clang v4 but still able to build those compatible binaries.

Note that you want to build using a host that is lower or same version as your minimum target version.

e.g. toolset-7 on host centos v6.7 will create bins compatible with 6.7, 6.9 and 7.x If your host is say centos 7.2 toolset-7 builds are only guaranteed to be compatible with v7.2+ targets.

Redhat's documentation is really good (and you can even get a free developer login to access more resources).

Also note that Centos provides similar options to RHEL.

The only downside is I don't think you can use the new ABI variant of CXX LIB as the ABI isn't compatible with older compilers like the default Centos gcc 4

Not really a problem as you can still use the C++11/14/17 features, just a few items are incompatible (such as list::size() still being O(n) and not const time, or strings still being COW)

https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/ (Lots of other tools/langs etc there too like Go,Rust,Python3 and lots of database updated versions etc.)

Not sure if you need to have a developer account, but an example of the documentation: https://access.redhat.com/documentation/en-us/red_hat_developer_toolset/7/html/7.0_release_notes/dts7.0_release