1、添加SCL软件源
yum install centos-release-scl
2、更改SCL软件源为国内镜像源
配置/etc/yum.repos.d/CentOS-SCLo-scl.repo为国内地址
[centos-sclo-sclo]
name=CentOS-7 – SCLo sclo
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
CentOS-SCLo-scl-rh.repo
配置/etc/yum.repos.d/CentOS-SCLo-scl-rh.repo为国内地址
[centos-sclo-rh]
name=CentOS-7 – SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
3、安装指定的gnu版本,例如:
yum install devtoolset-7
yum install devtoolset-8
yum install devtoolset-9
yum install devtoolset-10
yum install devtoolset-11
4、激活生效(以版本8示例)
scl enable devtoolset-8 bash
或
source /opt/rh/devtoolset-8/enable
5、验证gcc版本
此时通过gcc –version命令可以看到,gcc版本已经变成8.x.x
###值得注意的是这仅仅在当前bash生效,如果需要永久生效,可以请自行添加环境变量。