Skip to main content

环境安装

Centos7 安装gcc9

使用 Software Collections (SCL) 安装 devtoolset-9

sudo yum install -y centos-release-scl
sudo yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++

# 替换ailyun
# 1. 备份原有的源文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

# 2. 下载阿里云的 CentOS 7 源文件
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# 创建并编辑 SCLo 仓库文件
vim /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=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

sudo yum clean all
sudo yum makecache
sudo yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++


scl enable devtoolset-9 bash
gcc --version # 验证版本

如果你想永久生效,可以将启用命令添加到 ~/.bashrc 文件中:

echo 'source /opt/rh/devtoolset-9/enable' >> ~/.bashrc
source ~/.bashrc

apt unsecure

sudo apt update --allow-insecure-repositories

apt install iputils-ping --allow-unauthenticated