gcc升级(含命令行升级、手动升级两种方式)

打印 上一主题 下一主题

主题 497|帖子 497|积分 1491

1.yum源替换

默认yum源不可用,替换为国内源
替换前:

1.1 备份原始repo设置文件

  1. cd /etc/yum.repos.d/
  2. mkdir bak
  3. mv CentOS-* bak/
复制代码

1.2 重新设置CentOS-Base.reporepo文件

  1. 若服务器有wget命令,可复制下述命令直接从互联网拉取阿里配置源到服务器
  2. wget https://mirrors.aliyun.com/repo/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo
  3. 若服务器为最小化安装,没有wget命令,可以直接在/etc/yum.repos.d/目录下,创建名称为CentOS-Base.repo的文件,把下述内容复制到配置文件中
复制代码
CentOS-Base.reporepo全内容
  1. [base]
  2. name=CentOS-$releasever - Base - mirrors.aliyun.com
  3. failovermethod=priority
  4. baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
  5.         http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
  6.         http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
  7. gpgcheck=1
  8. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  9. #released updates
  10. [updates]
  11. name=CentOS-$releasever - Updates - mirrors.aliyun.com
  12. failovermethod=priority
  13. baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
  14.         http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
  15.         http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
  16. gpgcheck=1
  17. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  18. #additional packages that may be useful
  19. [extras]
  20. name=CentOS-$releasever - Extras - mirrors.aliyun.com
  21. failovermethod=priority
  22. baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
  23.         http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
  24.         http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
  25. gpgcheck=1
  26. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  27. #additional packages that extend functionality of existing packages
  28. [centosplus]
  29. name=CentOS-$releasever - Plus - mirrors.aliyun.com
  30. failovermethod=priority
  31. baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
  32.         http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
  33.         http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
  34. gpgcheck=1
  35. enabled=0
  36. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  37. #contrib - packages by Centos Users
  38. [contrib]
  39. name=CentOS-$releasever - Contrib - mirrors.aliyun.com
  40. failovermethod=priority
  41. baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
  42.         http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
  43.         http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
  44. gpgcheck=1
  45. enabled=0
  46. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
复制代码
修改后:

1.3 扫除缓存并重新创建

  1. yum clean all
  2. yum makecache
复制代码

2. gcc安装

  1. yum -y install gcc gcc-c++
复制代码
安装后,默认版本为:4.8.5

3.命令行升级gcc

  1. yum -y install centos-release-scl
  2. yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutilse
  3. scl enable devtoolset-9 bash
  4. echo "source /opt/rh/devtoolset-9/enable">> /etc/profile
复制代码
执行过程中出现非常信息:
1.安装:centos-release-scl时正常,安装:devtoolset-9-gcc、devtoolset-9-gcc-c++、devtoolset-9-binutilse时出现报错

办理方法: 检察报错信息,报错为:CentOS-SCLo-scl-rh.repo文件地址无法访问
利用阿里对应的设置文件,修改改文件内容
CentOS-SCLo-scl-rh.repo文件全内容
  1. [centos-sclo-rh]
  2. name=CentOS-$releasever - SCLo rh
  3. baseurl=https://mirrors.aliyun.com/centos/$releasever/sclo/$basearch/rh/
  4. gpgcheck=1
  5. enabled=1
  6. gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
复制代码
CentOS-SCLo-scl.repo文件内容
  1. [centos-sclo-sclo]
  2. name=CentOS-$releasever - SCLo sclo
  3. baseurl=https://mirrors.aliyun.com/centos/$releasever/sclo/$basearch/sclo/
  4. gpgcheck=1
  5. enabled=1
  6. gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
复制代码
2.扫除缓存,重新创建缓存后,再次安装devtoolset-9-gcc、devtoolset-9-gcc-c++、devtoolset-9-binutilse出现非常信息

办理方法: 检察报错信息为密钥题目,实验在安装时候,直接安装,不校验密钥
  1. yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutilse --nogpgcheck
复制代码
乐成安装

在当前shell终端中使devtoolset-9见效,设置永世利用devtoolset-9,检察gcc版本,已经乐成升级到9.3.1

4.手动升级

9.3.0为例
4.1 安装包下载

  1. # 创建存放目录
  2. mkdir -p /apps/scripts
  3. cd /apps/scripts/
  4. # gcc安装包下载
  5. 下载地址:https://mirrors.aliyun.com/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
  6. 可下载后上传,或直接在服务器上从互联网拉取
  7. wget https://mirrors.aliyun.com/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
复制代码

4.2 解压

  1. tar -xzf gcc-9.3.0.tar.gz
  2. cd gcc-9.3.0
复制代码

  1. [root@rhel76 gcc-10.1.0]# mkdir build
  2. [root@rhel76 gcc-10.1.0]# cd build/
  3. [root@rhel76 build]# …/configure --prefix=/usr/local/gcc-10.1.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib
复制代码
4.3 gcc升级

4.3.1 依靠拉取

  1. cd /apps/scripts/gcc-9.3.0/
  2. ./contrib/download_prerequisites
  3. // 在gcc-9.3.0目录下,多了gmp-6.1.0.tar.bz2、isl-0.18.tar.bz2、mpc-1.0.3.tar.gz、mpfr-3.1.4.tar.bz2四个压缩文件
  4. // 若已经安装了bzip2命令,则会自动解压上述压缩包
  5. // 演示环境为最小化安装,目前未安装bzip2命令
复制代码

4.3.2 gmp安装

解压gmp
  1. cd /apps/scripts/gcc-9.3.0/
  2. tar -xvjf gmp-6.1.0.tar.bz2
  3. 解压报错:
  4. tar (child): bzip2: Cannot exec: No such file or directory
  5. tar (child): Error is not recoverable: exiting now
  6. tar: Child returned status 2
  7. tar: Error is not recoverable: exiting now
复制代码

安装bzip2后,重新解压
  1. 安装bzip2
  2. yum -y install bzip2 m4
  3. // bzip2:解决上述报错  m4:解决configure过程中报错
  4. 继续安装gmp
  5. tar -xvjf gmp-6.1.0.tar.bz2
  6. cd /apps/scripts/gcc-9.3.0/gmp-6.1.0
  7. ./configure --prefix=/usr/local/gmp-6.1.0
  8. make
  9. make install
复制代码
解压完成

configure 完成

make完成

make install完成


4.3.3 mpfr安装

  1. cd /apps/scripts/gcc-9.3.0/
  2. tar -xvjf mpfr-3.1.4.tar.bz2
  3. cd mpfr-3.1.4
  4. ./configure --prefix=/usr/local/mpfr-3.1.4 --with-gmp=/usr/local/gmp-6.1.0
  5. make
  6. make install
复制代码
解压完成

configure 完成

make完成

make install 完成

4.3.4 mpc安装

  1. cd /apps/scripts/gcc-9.3.0/
  2. tar -xvf mpc-1.0.3.tar.gz
  3. cd mpc-1.0.3
  4. ./configure --prefix=/usr/local/mpc-1.0.3 --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.4
  5. make
  6. make install
复制代码
解压完成

configure 完成

make完成

make install 完成


4.3.5 gcc编译、安装

  1. cd /apps/scripts/gcc-9.3.0
  2. mkdir build
  3. cd build/
  4. ../configure --prefix=/usr/local/gcc-9.3.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.4 --with-mpc=/usr/local/mpc-1.0.3
  5. make
  6. yum -y remove gcc gcc-c++
  7. make install
复制代码
configure 完成

make完成–好久好久

build目次下对应文件巨细

旧版本删除完成

GCC安装完成

4.4 gcc命令设置

  1. ln -s /usr/local/gcc-9.3.0/bin/gcc /usr/bin/gcc
  2. ln -s /usr/local/gcc-9.3.0/bin/g++ /usr/bin/g++
  3. gcc -v
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

魏晓东

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表