Simply use dnf

Copydnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
source /opt/rh/gcc-toolset-9/enable

ref: https://centos.pkgs.org/8/centos-appstream-x86_64/gcc-toolset-9-gcc-9.1.1-2.4.el8.x86_64.rpm.html

Note: source won't work inside a Dockerfile so prefer to use:

CopyENV PATH=/opt/rh/gcc-toolset-9/root/usr/bin:$PATH

or better

CopyRUN dnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++

RUN echo "source /opt/rh/gcc-toolset-9/enable" >> /etc/bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN gcc --version
Answer from Mizux on Stack Overflow
🌐
Centos
lists.centos.org › pipermail › centos-devel › 2019-September › 017863.html
[CentOS-devel] CentOS 8 - Full SCL availability?
September 28, 2019 - On Fri, Sep 27, 2019 at 9:53 AM Thomas Oulevey <thomas.oulevey at cern.ch> wrote: > Hi Folks, > > > GCC 8 is the system compiler in EL8, so there's no devtoolset-8 for CentOS 8 (or RHEL 8, for that matter). There should be a devtoolset-9 soon for EL8. > > My understanding is that Application ...
Discussions

linux - Can not find required gcc version after devtoolset installation - Stack Overflow
I have followed instructions from How to install GCC/G++ 8 on CentOS · When I try scl enable devtoolset-8 -- bash, it shows · Unable to open /etc/scl/conf/devtoolset-8! Then I have checked in /etc/scl/conf/ where there is one file named 'devtoolset-9'. But I was expecting devtoolset-8. More on stackoverflow.com
🌐 stackoverflow.com
Installing devtoolset-X
$ sudo dnf search toolset Last metadata expiration check: 2:26:13 ago on Mon 15 Nov 2021 05:10:30 AM EST. ============================================= Name & Summary Matched: toolset ==== gcc-toolset-10.x86_64 : Package that installs gcc-toolset-10 gcc-toolset-10-runtime.x86_64 : Package that handles gcc-toolset-10 Software Collection. gcc-toolset-11.x86_64 : Package that installs gcc-toolset-11 gcc-toolset-11-runtime.x86_64 : Package that handles gcc-toolset-11 Software Collection. gcc-toolset-9.x86_64 : Package that installs gcc-toolset-9 gcc-toolset-9-runtime.x86_64 : Package that handles gcc-toolset-9 Software Collection. So do dnf-install gcc-toolset-X, then scl enable devtoolset-X bash More on reddit.com
🌐 r/AlmaLinux
1
7
November 14, 2021
linux - How to install gcc8 using devtoolset-8-gcc - Stack Overflow
I am using CentOS Linux release 7.3.1611 which has gcc 4.8.5 20150623 installed. I am looking for a way to install a newer version of gcc, specially 8.1. I found the following site on how to inst... More on stackoverflow.com
🌐 stackoverflow.com
How to install devtoolset-11 on Centos 8 Stream - Stack Overflow
I'd like to use devtoolset-11 on Centos Stream 8, but can't find any information on whether the Software Collection repositories are available for Centos Stream. The usual dnf install centos-releas... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
🌐
LinuxConfig
linuxconfig.org › home › install development tools on rhel 8 / centos 8
Install development tools on RHEL 8 / CentOS 8
September 22, 2025 - Learn how to install Development Tools on RHEL 8. Follow steps to list, install, and remove using the dnf command. Ideal for system admins.
🌐
Hacker News
news.ycombinator.com › item
From the article *"past several years figuring out things like how to build newe... | Hacker News
March 19, 2021 - This is much easier to solve in CentOS and RHEL than building new tools. Redhat has done this for you. If you are a developer and need newer build tools, enable the SCLO repo · yum install centos-release-scl && yum install devtoolset-9 Or devtoolset-8, whichever has the versions of tools you need.
🌐
CentOS Repositories
centos.pkgs.org › 7 › centos-sclo-rh-x86_64 › devtoolset-9-gdb-8.3-3.el7.x86_64.rpm.html
devtoolset-9-gdb-8.3-3.el7.x86_64.rpm - CentOS Repositories
2019-08-01 - Keith Seitz <keiths@redhat.com> - devtoolset-9.0 8.3-3.el7 - Include performance regression patch (sw symtab/24545)
🌐
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.
Find elsewhere
🌐
Abysm
blog.abysm.org › 2016 › 03 › installing-developer-toolset-rhel-based-distributions
Installing Developer Toolset on RHEL-based Distributions · Kuan-Yi Li's Blog
March 25, 2016 - yum install centos-release-scl · yum install yum-conf-repos yum install yum-conf-softwarecollections · yum install "http://ftp.scientificlinux.org/linux/scientific/6/external_products/softwarecollections/yum-conf-softwarecollections-2.0-1.el6.noarch.rpm" Install the version(s) of your choice. Yes, they can co-exist. yum install devtoolset-10 · yum install devtoolset-9 · yum install devtoolset-8 ·
🌐
ComputingForGeeks
computingforgeeks.com › home › install gcc and development tools on rhel 8 / centos 8
Install GCC and Development Tools on RHEL 8 / CentOS 8 [Guide]
August 17, 2023 - Step-by-step guide to gCC and Development Tools on RHEL 8 / CentOS 8. Includes commands, verification, and troubleshooting.
🌐
Centos
lists.centos.org › hyperkitty › list › discuss@lists.centos.org › thread › MMFVAGPPWI5A5PIUX5VYGFITADSYWSO5
gcc 8/9 on CentOS 7 - Discuss - lists.centos.org
I am looking to make use of gcc 8/9 on CentOS 7, which is currently with gcc 4.8.5. How do I go about doing this? SCL repository provides the same as part of devtoolset8, but devtoolset8 libstdc++-devel i686 package is missing, without which I can not build 32 bit applications.
Top answer
1 of 4
25

What I have so far:

cat Dockerfile

FROM centos:7 AS env

RUN yum update -y
RUN yum install -y centos-release-scl
RUN yum install -y devtoolset-9

RUN echo "source /opt/rh/devtoolset-9/enable" >> /etc/bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN gcc --version

So you must:

  1. Add the source stuff in a bashrc
    note: On Centos it's /etc/bashrc while on ubuntu it's /etc/bash.bashrc

  2. Update the docker default shell to be bash AND to "load" the bashrc using --login

Output

docker build .
Sending build context to Docker daemon  4.096kB
Step 1/32 : FROM centos:7 AS env
 ---> 8652b9f0cb4c
Step 2/32 : RUN yum update -y
 ---> Using cache
 ---> a2bb269cd8dc
Step 3/32 : RUN yum install -y centos-release-scl
 ---> Using cache
 ---> 1184e26c71cf
Step 4/32 : RUN yum install -y devtoolset-9
 ---> Using cache
 ---> e678665d2a4e
Step 5/32 : RUN echo "source /opt/rh/devtoolset-9/enable" >> /etc/bashrc
 ---> Using cache
 ---> fe1745d4ca87
Step 6/32 : SHELL ["/bin/bash", "--login", "-c"]
 ---> Running in 2dd7955f4487
Removing intermediate container 2dd7955f4487
 ---> 3cf4835bf680
Step 7/32 : RUN gcc --version
 ---> Running in b5de3266d607
gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
Copyright (C) 2019 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.
 ...

What won't work

Test 1

RUN scl enable devtoolset-9 bash
RUN gcc --version | head -1

each RUN is a new shell so the sub-bash is lost on the second line.

Test 2

RUN source /opt/rh/devtoolset-9/enable && gcc --version | head -1
RUN gcc --version | head -1

Here again the source is only for the first RUN shell command but will be lost...

Test 3

This may work but with potential unexpected behaviour

ENV PATH=/opt/rh/devtoolset-9/root/bin:$PATH
RUN gcc --version | head -1

here we only "fix" the PATH variable but if you look at the /opt/rh/devtoolset-9/enable script there is so more to do than only updating the PATH...

2 of 4
0

You may give it a try using the below steps if that may help: Download the latest package from http://ftp.gnu.org/gnu/gcc/gcc-9.2.0/

wget http://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz

Extract the files using the steps below:

tar -xzvf gcc-9.20.tar.gz
cd gcc-9.2.0

Build a configuration using the below,

./configure

Compile the installation using make and then make install.

make 
make install