How to Upgrade GCC on CentOS 7 & 8 Using Red Hat Developer Toolset
This guide explains why you should avoid compiling GCC yourself and shows step‑by‑step how to use Red Hat's Developer Toolset or gcc‑toolset to install, switch, and activate newer GCC versions on both CentOS 7 and CentOS 8, including temporary and permanent activation methods.
CentOS 7 Upgrade GCC Version
Red Hat provides a Developer Toolset that lets you manage GCC versions without recompiling, allowing multiple versions to coexist and be switched on demand.
Mapping of devtoolset packages to GCC versions:
devtoolset-3 → GCC 4.x.x
devtoolset-4 → GCC 5.x.x
devtoolset-6 → GCC 6.x.x
devtoolset-7 → GCC 7.x.x
devtoolset-8 → GCC 8.x.x
devtoolset-9 → GCC 9.x.x
devtoolset-10 → GCC 10.x.xInstall devtoolset on CentOS 7 via the centos-release-scl repository:
yum install centos-release-scl
yum install devtoolset-8Or add the repository manually (example for CentOS 7):
vi /etc/yum.repos.d/CentOS-SCLo-scl.repo
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/rh/
#mirrorlist=...
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLoActivate the new GCC version for the current session:
scl enable devtoolset-8 bash
# or
source /opt/rh/devtoolset-8/enableRunning gcc --version now shows GCC 8.x.x. This change is only effective for the current shell; to make it permanent, add the appropriate environment variables to your profile.
CentOS 8 Upgrade GCC
CentOS 8 ships with GCC 8.x.x by default, but higher versions can be installed via Red Hat's gcc‑toolset packages.
Mapping of gcc‑toolset packages to GCC versions:
gcc-toolset-9 → GCC 9.x.x
gcc-toolset-10 → GCC 10.x.x
gcc-toolset-11 → GCC 11.x.xExample: Upgrade to GCC 10.x.x
1. Configure YUM/DNF repository
vim /etc/yum.repos.d/Centos-8.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-$releasever - AppStream - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
[8-AppStream]
name=CentOS-$releasever - 8-AppStream
baseurl=http://mirrors.aliyun.com/centos/8-stream/AppStream/$basearch/os/
gpgcheck=0
enabled=12. Install gcc‑toolset‑10
dnf install gcc-toolset-103. Activate the new GCC version
scl enable gcc-toolset-10 bash
# or
source /opt/rh/gcc-toolset-10/enableAfter activation, gcc --version reports GCC 10.x.x. As with CentOS 7, this activation is session‑only; add the enable script to your shell startup files for a permanent change.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
