资讯专栏INFORMATION COLUMN

CentOS 7 升级 gcc

Tecode / 2418人阅读

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

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

</>复制代码

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

安装 SCL 源

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

</>复制代码

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

更换国内镜像源

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

</>复制代码

  1. # 清华大学
  2. sed -i s+#baseurl=http://mirror.centos.org+baseurl=https://mirrors.tuna.tsinghua.edu.cn+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
  3. sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
  4. sed -i s+# baseurl=http://mirror.centos.org+baseurl=https://mirrors.tuna.tsinghua.edu.cn+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
  5. sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
  6. # 阿里云
  7. sed -i s+#baseurl=http://mirror.centos.org+baseurl=https://mirrors.aliyun.com+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
  8. sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
  9. sed -i s+# baseurl=http://mirror.centos.org+baseurl=https://mirrors.aliyun.com+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
  10. sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
  11. # 腾讯云
  12. sed -i s+#baseurl=http://mirror.centos.org+baseurl=https://mirrors.cloud.tencent.com+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
  13. sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
  14. sed -i s+# baseurl=http://mirror.centos.org+baseurl=https://mirrors.cloud.tencent.com+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
  15. sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
  16. # 腾讯云内网
  17. sed -i s+#baseurl=http://mirror.centos.org+baseurl=https:///mirrors.tencentyun.com+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
  18. sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
  19. sed -i s+# baseurl=http://mirror.centos.org+baseurl=https:///mirrors.tencentyun.com+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
  20. sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
  21. # 阿里云内网
  22. sed -i s+#baseurl=http://mirror.centos.org+baseurl=https://mirrors.cloud.aliyuncs.com+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
  23. sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
  24. sed -i s+# baseurl=http://mirror.centos.org+baseurl=https://mirrors.cloud.aliyuncs.com+ /etc/yum.repos.d/CentOS-SCLo-scl.repo
  25. sed -i s+mirrorlist=+#mirrorlist=+ /etc/yum.repos.d/CentOS-SCLo-scl.repo

替换后的文件内容如下。

</>复制代码

  1. # CentOS-SCLo-sclo.repo
  2. #
  3. # Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
  4. # information
  5. [centos-sclo-sclo]
  6. name=CentOS-7 - SCLo sclo
  7. baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/sclo/$basearch/sclo/
  8. #mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
  9. gpgcheck=1
  10. enabled=1
  11. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
  12. [centos-sclo-sclo-testing]
  13. name=CentOS-7 - SCLo sclo Testing
  14. baseurl=http://buildlogs.centos.org/centos/7/sclo/$basearch/sclo/
  15. gpgcheck=0
  16. enabled=0
  17. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
  18. [centos-sclo-sclo-source]
  19. name=CentOS-7 - SCLo sclo Sources
  20. baseurl=http://vault.centos.org/centos/7/sclo/Source/sclo/
  21. gpgcheck=1
  22. enabled=0
  23. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
  24. [centos-sclo-sclo-debuginfo]
  25. name=CentOS-7 - SCLo sclo Debuginfo
  26. baseurl=http://debuginfo.centos.org/centos/7/sclo/$basearch/
  27. gpgcheck=1
  28. enabled=0
  29. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

</>复制代码

  1. # CentOS-SCLo-sclo.repo
  2. #
  3. # Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
  4. # information
  5. [centos-sclo-sclo]
  6. name=CentOS-7 - SCLo sclo
  7. # baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/sclo/
  8. mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
  9. gpgcheck=1
  10. enabled=1
  11. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
  12. [centos-sclo-sclo-testing]
  13. name=CentOS-7 - SCLo sclo Testing
  14. baseurl=http://buildlogs.centos.org/centos/7/sclo/$basearch/sclo/
  15. gpgcheck=0
  16. enabled=0
  17. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
  18. [centos-sclo-sclo-source]
  19. name=CentOS-7 - SCLo sclo Sources
  20. baseurl=http://vault.centos.org/centos/7/sclo/Source/sclo/
  21. gpgcheck=1
  22. enabled=0
  23. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
  24. [centos-sclo-sclo-debuginfo]
  25. name=CentOS-7 - SCLo sclo Debuginfo
  26. baseurl=http://debuginfo.centos.org/centos/7/sclo/$basearch/
  27. gpgcheck=1
  28. enabled=0
  29. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

更新软件包缓存

</>复制代码

  1. yum makecache fast

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

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

</>复制代码

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

安装软件包

</>复制代码

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

切换 gcc 版本

</>复制代码

  1. // 临时有效,退出 shell 或重启会恢复原 gcc 版本
  2. scl enable devtoolset-9 bash
  3. // 长期有效
  4. echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

此时再查看 gcc 版本。

</>复制代码

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

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

</>复制代码

  1. $ scl -l
  2. 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元查看
<