资讯专栏INFORMATION COLUMN

CentOS 7 升级 gcc

Tecode / 1937人阅读

摘要:我们在需要升级的版本。但是为了软件的稳定和版本支持,上版本也是,所以无法使用进行软件更新,需要安装源升级。更换国内镜像源执行替换命令将软件仓库地址替换为国内镜像地址。

Centos7 gcc 版本默认 4.8.5,而有些软件(例如:Redis6、Mariadb10 等)的编译安装需要最低支持 c++11 的 gcc 5.x 版本。我们在需要升级 gcc 的版本。但是 Red Hat 为了软件的稳定和版本支持,yum 上版本也是 4.8.5,所以无法使用 yum 进行软件更新,需要安装 SCL 源升级 gcc。

$ gcc -v
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)

安装 SCL 源

SCL 软件集(Software Collections),是为了给 RHEL/CentOS 用户提供一种以方便、安全地安装和使用应用程序和运行时环境的多个(而且可能是更新的)版本的方式,同时避免把系统搞乱。

yum install -y centos-release-scl scl-utils-build

更换国内镜像源

执行替换命令将软件仓库地址替换为国内镜像地址。

# 清华大学
sed -i s+#baseurl=http://mirror.centos.org+baseurl=https://mirrors.tuna.tsinghua.edu.cn+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i s+# baseurl=http://mirror.centos.org+baseurl=https://mirrors.tuna.tsinghua.edu.cn+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl.repo

# 阿里云
sed -i s+#baseurl=http://mirror.centos.org+baseurl=https://mirrors.aliyun.com+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i s+# baseurl=http://mirror.centos.org+baseurl=https://mirrors.aliyun.com+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl.repo

# 腾讯云
sed -i s+#baseurl=http://mirror.centos.org+baseurl=https://mirrors.cloud.tencent.com+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i s+# baseurl=http://mirror.centos.org+baseurl=https://mirrors.cloud.tencent.com+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl.repo

# 腾讯云内网
sed -i s+#baseurl=http://mirror.centos.org+baseurl=https:///mirrors.tencentyun.com+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i s+# baseurl=http://mirror.centos.org+baseurl=https:///mirrors.tencentyun.com+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl.repo

# 阿里云内网
sed -i s+#baseurl=http://mirror.centos.org+baseurl=https://mirrors.cloud.aliyuncs.com+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i s+# baseurl=http://mirror.centos.org+baseurl=https://mirrors.cloud.aliyuncs.com+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl.repo

替换后的文件内容如下。

# CentOS-SCLo-sclo.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information

[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/sclo/$basearch/sclo/
#mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-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=http://buildlogs.centos.org/centos/7/sclo/$basearch/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=http://vault.centos.org/centos/7/sclo/Source/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=http://debuginfo.centos.org/centos/7/sclo/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
# 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://mirror.centos.org/centos/7/sclo/$basearch/sclo/
mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-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=http://buildlogs.centos.org/centos/7/sclo/$basearch/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=http://vault.centos.org/centos/7/sclo/Source/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=http://debuginfo.centos.org/centos/7/sclo/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

更新软件包缓存

yum makecache fast

查看源中关于 devtoolset-gcc 的软件包

devtoolset (Developer Toolset)是按照 Software Collections 的规范打出来的一套 rpm 包,提供了最新版本的 GNU 编译器集合,GNU 调试器以及其他开发,调试和性能监视工具。

# yum list all --enablerepo=centos-sclo-rh | grep devtoolset-9-gcc
Repository epel is listed more than once in the configuration
devtoolset-9-gcc.x86_64                    9.3.1-2.el7            centos-sclo-rh
devtoolset-9-gcc-c++.x86_64                9.3.1-2.el7            centos-sclo-rh
devtoolset-9-gcc-gdb-plugin.x86_64         9.3.1-2.el7            centos-sclo-rh
devtoolset-9-gcc-gfortran.x86_64           9.3.1-2.el7            centos-sclo-rh
devtoolset-9-gcc-plugin-devel.x86_64       9.3.1-2.el7            centos-sclo-rh

安装软件包

yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

切换 gcc 版本

// 临时有效,退出 shell 或重启会恢复原 gcc 版本
scl enable devtoolset-9 bash

// 长期有效
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

此时再查看 gcc 版本。

$ gcc -v
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)

查看从 SCL 源中安装的软件包

$ scl -l
devtoolset-9

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/125969.html

相关文章

  • CentOS6.5升级安装Python3.3版本且保留原版本Python2.x

    摘要:如果我们是新服务器重新配置,那就可以只安装一个新版本。第一服务器升级图片描述这里会自动安装且检测最新版本。如果我们以后需要执行版本的话,可以这样脚本。这样,我们是不是很简单的就可以将当前系统已有的版本保留且安装到默认版本。 目前服务器的系统是CENTOS6.5版本镜像,已有软件是在Python2.7.5默认环境中运行,但是由于有一个新的工具脚本需要在Python3.x版本中运行,这里需...

    BakerJ 评论0 收藏0
  • Elam的caffe笔记之配置篇(一):CentOS6.5编译安装gcc4.8.2

    配置要求: 系统:centos6.5 目标:基于CUDA8.0+Opencv3.1+Cudnnv5.1+python3.6接口的caffe框架 gcc是linux编译安装必备的编译器 CentOS6.5自带的gcc版本是4.4.7,并不支持C++11查询后可得需要版本高于4.8.1的gcc才能支持C++11输入 yum info gcc 发现可升级的gcc版本低于4.8.1,只能手动编译安装4....

    wing324 评论0 收藏0
  • Centos 7离线安装Nginx 配置负载均衡集群

    摘要:安装安装验证其它依赖包安装警告头密钥准备中正在升级安装警告头密钥准备中正在升级安装安装安装好上述依赖包后就可以安装了。安装如下使用将解压到目录,编译安装配置安装好后我们需要对进行配置。 场景 项目中有三台应用服务器,系统为Centos 7 ,应用地址分别为: 192.168.198.229:8080 192.168.198.230:8080 192.168.198.231:8080 ...

    shadowbook 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<