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

Answer from Mizux on Stack Overflow
🌐
CentOS Repositories
centos.pkgs.org › 7 › centos-sclo-rh-x86_64 › devtoolset-9-9.0-3.el7.x86_64.rpm.html
devtoolset-9-9.0-3.el7.x86_64.rpm - CentOS Repositories
This is the main package for devtoolset-9 Software Collection. Install CentOS SCLo RH repository: yum install centos-release-scl-rh · Install devtoolset-9 rpm package: # yum install devtoolset-9 · 2019-10-23 - Frank Ch. Eigler <fche@redhat.com> - 9.0-3 - implement better sudo wrapper (#1319936) ...
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 
🌐
GitHub
gist.github.com › superzscy › ea619f881c92b8cdae8faaf782d0f031
Installing-GCC-9-on-CentOS-7.md · GitHub
yum install -y centos-release-scl yum install -y devtoolset-9 scl enable devtoolset-9 bash
🌐
CentOS Repositories
centos.pkgs.org › 7 › centos-sclo-rh-testing-x86_64 › devtoolset-9-9.0-3.el7.x86_64.rpm.html
devtoolset-9-9.0-3.el7.x86_64.rpm CentOS 7 Download
This is the main package for devtoolset-9 Software Collection. Install CentOS SCLo RH Testing repository: yum install centos-release-scl-rh · Install devtoolset-9 rpm package: # yum --enablerepo=centos-sclo-rh-testing install devtoolset-9 · 2019-10-23 - Frank Ch.
🌐
Ucsd
browndye.ucsd.edu › download.html
Download & Installation
yum install centos-release-scl epel-release yum install devtoolset-9 ocaml expat-devel lapack-devel apbs scl enable devtoolset-9 bash
🌐
CentOS Repositories
centos.pkgs.org › 7 › centos-sclo-rh-x86_64 › devtoolset-9-toolchain-9.0-3.el7.x86_64.rpm.html
devtoolset-9-toolchain-9.0-3.el7.x86_64.rpm CentOS 7 Download
devtoolset-9-toolchain - Package shipping basic toolchain applications · Package shipping basic toolchain applications (compiler, debugger, ...) Install CentOS SCLo RH repository: yum install centos-release-scl-rh · Install devtoolset-9-toolchain rpm package: # yum install devtoolset-9-toolchain ...
🌐
Centos
cbs.centos.org › koji › buildinfo
devtoolset-9-gcc-9.3.1-2.2.el7 | Build Info | CentOS Community Build Service
August 5, 2021 - Main Site Links: · Summary · Packages · Builds · Tasks · Build Targets · Users · Hosts · Reports · Search
🌐
Red Hat
access.redhat.com › documentation › en-us › 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
August 7, 2020 - Note that error messages related to a missing libitm library when using the -fgnu-tm option require the libitm package to be installed. You can install the package with the following command: ... To use the ccache utility with GCC included in Red Hat Developer Toolset, set your environment correctly. For example: ~]$ scl enable devtoolset-9 '/usr/lib64/ccache/gcc -c foo.c'
Find elsewhere
🌐
GitHub
gist.github.com › nchaigne › ad06bc867f911a3c0d32939f1e930a11
Building GCC 9.2.0 on CentOS 7 · GitHub
Great guide. To enable gcc 9 as default, may have to run the following commands: sudo yum install devtoolset-9-toolchain scl enable devtoolset-9 bash
🌐
Anl
polaris.taps.anl.gov › polaris › development › setup › centos.html
CentOS 7 — Polaris 26.02 documentation
sudo yum update sudo yum group install "Development Tools" sudo yum install centos-release-scl sudo yum-config-manager --enable rhel-server-rhscl-7-rpms sudo yum install devtoolset-9 sudo yum install devtoolset-9-gcc-plugin-devel scl enable devtoolset-9 bash # You can add this the line below ...
🌐
Posit Support
support.posit.co › hc › en-us › articles › 360006145413-Posit-Workbench-with-devtoolset-enabled
Posit Workbench with devtoolset enabled – Posit Support
January 24, 2025 - yum install centos-release-scl · yum install devtoolset-9 · Execute: gcc --version · Enable devtoolset-10 with: source scl_source enable devtoolset-9 · Review gcc version now with: gcc --version · Once tested, you can implement this on ...
🌐
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 - Because using such a package with multiple complex packages you must configure multiple environment and links to the versions you installed replacing the ones from your base system, but the package comes with a handy tool, which executing it will configure everything and you are ready to go! ... 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, Inc.
🌐
Nasa
seadas.gsfc.nasa.gov › build_ocssw › rhel
NASA Ocean Color - SeaDAS
Get a newer compiler. This gives us gcc-9.3.1 · yum install centos-release-scl yum install devtoolset-9 yum install bison flex zlib-devel.x86_64 libX11-devel.x86_64 patch scl enable devtoolset-9 bash yum install python3 pip3 install requests
🌐
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.
🌐
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 ...el6.noarch.rpm" Install the version(s) of your choice. Yes, they can co-exist. yum install devtoolset-10 · yum install devtoolset-9 ·...
🌐
Red Hat
access.redhat.com › solutions › 6607901
How to install devtoolset-9 in RHEL Workstation? - Red Hat Customer Portal
Unable to install devtoolset-9 in RHEL Workstation. # yum install devtoolset-9 Loaded plugins: langpacks, product-id, search-disabled-repos, subscription- : manager No package devtoolset-9
🌐
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.