SCL方式安装GCC
# 手动调整 SCL YUM 源
# CentOS 7 最晚在2024年6月30后停止更新维护,所以在 CentOS 7 直接通过 yum 直接安装 SCL 源是会失败的,所以需要手动调整 SCL YUM 源。
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
cat > /etc/yum.repos.d/CentOS-SCLo-scl.repo << EOF
# CentOS-SCLo-sclo.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
#baseurl=http://vault.centos.org/centos/7/sclo/$basearch/sclo/
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/sclo/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-sclo-testing]
name=CentOS-7 - SCLo sclo Testing
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/sclo/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-sclo-source]
name=CentOS-7 - SCLo sclo Sources
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/sclo/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-sclo-debuginfo]
name=CentOS-7 - SCLo sclo Debuginfo
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/sclo/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
EOF
cat > /etc/yum.repos.d/CentOS-SCLo-rh.repo << EOF
# CentOS-SCLo-rh.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/rh/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-testing]
name=CentOS-7 - SCLo rh Testing
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/rh/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-source]
name=CentOS-7 - SCLo rh Sources
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/rh/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-debuginfo]
name=CentOS-7 - SCLo rh Debuginfo
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/rh/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
EOF
# 安装依赖包
yum clean all
yum makecache
# 查看已安装的scl
scl --list
# 卸载安装的scl
yum remove devtoolset-8\*
# 安装依赖包
yum install -y wget gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel bison bison-devel zlib-devel bzip2
yum install -y libcurl-devel libarchive-devel boost-devel gnutls-devel libxml2-devel libevent-devel perl-Data-Dumper libtirpc-devel
yum install -y scl-utils scl-utils-build
yum install -y centos-release-scl centos-release-scl-rh
yum install -y devtoolset-11-binutils devtoolset-11-gcc devtoolset-11-gcc-c++ devtoolset-11-gcc-gfortran
# 在shell中直接启用新版本gcc11
scl enable devtoolset-11 bash
echo "source /opt/rh/devtoolset-11/enable" >> /etc/profile
# 替换库链接
rm -f /usr/lib64/libstdc++.so.6
ln -s /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libstdc++.so /usr/lib64/libstdc++.so.6
# 检查验证 gcc 版本
gcc -v