Docs/linux基础/Centos7升级gcc版本.md

48 lines
No EOL
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

**Red Hat Developer Toolset是RedHat开发工具包可以多版本gcc共存不影响原系统gcc环境**
## 安装Red Hat Developer Toolset
```shell
yum -y install centos-release-scl-rh
```
## 配置软件源
```shell
cat > CentOS-SCLo-scl-rh.repo << EOF
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/sclo/$basearch/rh/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
EOF
```
## 生成缓存
```shell
yum makecache
```
## 安装相应版本
```
# devtoolset-3对应gcc4.x.x版本
# devtoolset-4对应gcc5.x.x版本
# devtoolset-6对应gcc6.x.x版本
# devtoolset-7对应gcc7.x.x版本
# devtoolset-8对应gcc8.x.x版本
# devtoolset-9对应gcc9.x.x版本
# devtoolset-10对应gcc10.x.x版本
# 安装gcc-10
yum -y install devtoolset-10
```
## 使gcc版本生效
```shell
# 以下两条命令效果相同
# 只在当前shell中生效
scl enable devtoolset-8 bash
source /opt/rh/devtoolset-8/enable
# 当前用户生效
cat >> ~/.bash_profile << EOF
source /opt/rh/devtoolset-8/enable
EOF
```