Install it by:

sudo yum install centos-release-scl
sudo yum install devtoolset-4

The first command installs and enables Software Collections Repository on your CentOS machine. That repository provides the devtoolset package.

Answer from 13dimitar on Stack Exchange
🌐
Softwarecollections
softwarecollections.org › en › scls › rhscl › devtoolset-8
Developer Toolset 8 — Software Collections
devtoolset-8 - Developer Toolset is designed for developers working on CentOS or Red Hat Enterprise Linux platform.
🌐
Softwarecollections
softwarecollections.org › en › scls › rhscl › devtoolset-7
Developer Toolset 7 — Software Collections
devtoolset-7 - Developer Toolset is designed for developers working on CentOS or Red Hat Enterprise Linux platform.
🌐
Docker Hub
hub.docker.com › r › centos › devtoolset-7-toolchain-centos7
centos/devtoolset-7-toolchain-centos7 - Docker Image
FROM rhscl/devtoolset-7-toolchain-rhel7 USER 0 RUN yum install -y --setopt=tsflags=nodocs boost-devel && yum clean all -y USER 1001 Copy
🌐
Stack Overflow
stackoverflow.com › questions › 53708189 › how-to-install-devtoolset-7-i686-on-centos-6
centos6 - How to install devtoolset-7 i686 on CentOS 6? - Stack Overflow
yum --disablerepo=\* --enablerepo=cloudlinux install devtoolset-4-gcc devtoolset-4-gcc-c++ devtoolset-4-binutils scl enable devtoolset root@/etc/yum.repos.d $ gcc --version gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) Copyright (C) 2015 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. > Reference: Centos6安装gcc4.8及以上版本 (Chinese)
Find elsewhere
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
🌐
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 - [srv@local ~]# yum -y install centos-release-scl Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.crazyfrogs.org * extras: centos.quelquesmots.fr * updates: centos.mirror.fr.planethoster.net Resolving Dependencies --> Running transaction check ---> Package centos-release-scl.noarch 0:2-2.el7.centos will be installed --> Processing Dependency: centos-release-scl-rh for package: centos-release-scl-2-2.el7.centos.noarch --> Running transaction check ---> Package centos-release-scl-rh.noarch 0:2-2.el7.centos will be installed --> Finished Dependency Resolutio
Top answer
1 of 1
1

This issue in this case is RedHat subscription channels. Though the subscription and software are free (provided you have an active subscription already), for some reason you have to make a 'special request' to RedHat as per:

https://access.redhat.com/solutions/472793

You can automate this by visiting:

https://www.redhat.com/wapps/try/RHSCL

(when logged into the support portal). This should automatically be approved after which you can attach a new subscription. Identify the pool id using:

subscription-manager list --available --all

To find the pool id:

 Subscription Name:   Software Collections and Developer Toolset
 Provides:            Red Hat Developer Tools (for RHEL Server)
                      Red Hat Developer Tools Beta (for RHEL Workstation)
                      Red Hat Software Collections Beta (for RHEL Server)
                      Red Hat Software Collections Beta (for RHEL Workstation)
                      Red Hat Software Collections (for RHEL Server)
                      Red Hat Developer Tools Beta (for RHEL Server)
                      Red Hat Developer Toolset (for RHEL Workstation)
                      Red Hat Software Collections Beta (for RHEL Client)
                      Red Hat Software Collections (for RHEL Workstation)
                      Red Hat Developer Toolset (for RHEL Server)
                      Red Hat Developer Tools (for RHEL Workstation)
                      Red Hat Software Collections (for RHEL Client) 
SKU:                 foobar 
Contract:            1234 Pool ID: XXXXXXXXXX

Then attach this and enable the newly available repos:

>subscription-manager attach --pool=XXXXXXXXXXXXXXXXXXXX
Successfully attached a subscription for: Software Collections and Developer Toolset
>subscription-manager repos --enable rhel-workstation-rhscl-7-rpms
Repository 'rhel-workstation-rhscl-7-rpms' is enabled for this system.
>subscription-manager repos --enable rhel-7-workstation-devtools-rpms
Repository 'rhel-7-workstation-devtools-rpms' is enabled for this system.

You can now install freely:

>yum update -y 
>yum install -y devtoolset-7-gcc-c++

Quite why they make you jump through so many hoops is explained by RedHat as follows:

-If you have a 2013 RHEL SKU with Standard or Premium service level, there should be no action on your part, and your subscription should have full access to RHSCL.

-If you have a 2010 or older RHEL SKU with Standard or Premium service level, you should contact Red Hat Customer Service to request the RHSCL SKU (and all related content) added to your account.

NOTE: Developer Toolset is now included as part of Red Hat Software Collections. This change was made on May 29, 2014.

As you had Red Hat Enterprise Linux Workstation, Standard subscription which is older RHEL SKU with Standard service level, you had to initiate a special request for it

🌐
Docker Hub
hub.docker.com › r › centos › devtoolset-6-toolchain-centos7
centos/devtoolset-6-toolchain-centos7 - Docker Image
FROM rhscl/devtoolset-6-toolchain-rhel7 USER 0 RUN yum install -y --setopt=tsflags=nodocs boost-devel && yum clean all -y USER 1001 Copy
🌐
GitHub
gist.github.com › superzscy › ea619f881c92b8cdae8faaf782d0f031
Installing-GCC-9-on-CentOS-7.md · GitHub
If you restart the shell, it will revert to GCC 4.8.5. You can add "source /opt/rh/devtoolset-9/enable" into you bashrc file to set GCC 9 as the default.
🌐
Google Groups
groups.google.com › g › vfx-platform-discuss › c › _-_CPw1fD3c
Removal of Devtoolset-6 from CentOS 7.7
When a new CentOS version is released, the prior point release is left up for a temporary time before being archived. 7.6.1810 is currently in the process of being archived and will soon be unavailable from the original mirror. The new home of the DTS will be here: http://vault.centos.org/7.6.1810/sclo/x86_64/rh/devtoolset-6/ Cheers, Mike
Top answer
1 of 5
93

In your ~/.bashrc or ~/.bash_profile Simply source the "enable" script provided with the devtoolset. For example, with the Devtoolset 2, the command is:

source /opt/rh/devtoolset-2/enable

or

source scl_source enable devtoolset-2

Lot more efficient: no forkbomb, no tricky shell

2 of 5
17

An alternative of source /opt/rh/devtoolset-4/enable is

source scl_source enable devtoolset-4

The above shell script scl_source is more elegant than using a hard coded path (may be different on another machine). However scl_source does less because /opt/rh/devtoolset-4/enable uses scl_source and other stuff.

To use scl_source you may have to upgrade package scl-utils

yum update scl-utils  # old scl-utils versions miss scl_source

Quick copy-paste

echo 'source scl_source enable devtoolset-4' >> ~/.bashrc
    # Do not forget to change the version ↑

Source code for curious people

An example of scl_source source code:
https://gist.github.com/bkabrda/6435016

The scl_source installed on my Red Hat 7.1

#!/bin/bash

_scl_source_help="Usage: source scl_source <action> [<collection> ...]

Don't use this script outside of SCL scriptlets!

Options:
    -h, --help    display this help and exit"

if [ $# -eq 0 -o $1 = "-h" -o $1 = "--help" ]; then
    echo "$_scl_source_help"
    return 0
fi


if [ -z "$_recursion" ]; then
    _recursion="false"
fi
if [ -z "$_scl_scriptlet_name" ]; then
    # The only allowed action in the case of recursion is the same
    # as was the original
    _scl_scriptlet_name=$1
fi
shift 1

if [ -z "$_scl_dir" ]; then
    # No need to re-define the directory twice
    _scl_dir=/etc/scl/conf
    if [ ! -e $_scl_dir ]; then
        _scl_dir=/etc/scl/prefixes
    fi
fi

for arg in "$@"; do
    _scl_prefix_file=$_scl_dir/$arg
    _scl_prefix=`cat $_scl_prefix_file 2> /dev/null`
    if [ $? -ne 0 ]; then
        echo "Can't read $_scl_prefix_file, $arg is probably not installed."
        return 1
    fi

    # First check if the collection is already in the list
    # of collections to be enabled
    for scl in ${_scls[@]}; do
        if [ $arg == $scl ]; then
            continue 2
        fi
    done

    # Now check if the collection isn't already enabled
    /usr/bin/scl_enabled $arg > /dev/null 2> /dev/null
    if [ $? -ne 0 ]; then
        _scls+=($arg)
        _scl_prefixes+=($_scl_prefix)
    fi;
done

if [ $_recursion == "false" ]; then
    _i=0
    _recursion="true"
    while [ $_i -lt ${#_scls[@]} ]; do
        _scl_scriptlet_path="${_scl_prefixes[$_i]}/${_scls[$_i]}/${_scl_scriptlet_name}"
        source "$_scl_scriptlet_path"
        if [ $? -ne 0 ]; then
            echo "Can't source $_scl_scriptlet_name, skipping."
        else
            export X_SCLS="${_scls[$_i]} $X_SCLS"
        fi;
        _i=$(($_i+1))
    done
    _scls=()
    _scl_prefixes=()
    _scl_scriptlet_name=""
    _recursion="false"
fi
🌐
Centos
buildlogs.centos.org › c7-devtoolset-12.x86_64
Index of /c7-devtoolset-12.x86_64
This server contains a mix of raw/unsigned packages and/or build logs It should be used mainly for testing purposes