第1步:获取repo
[root@localhost SPECS]# wget --no-check-certificate https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo -O /etc/yum.repos.d/devtoolset-3.repo
--2021-12-07 20:53:26-- https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo
Resolving copr.fedoraproject.org (copr.fedoraproject.org)... 13.212.21.54, 13.233.183.170, 13.250.126.156, ...
Connecting to copr.fedoraproject.org (copr.fedoraproject.org)|13.212.21.54|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://copr.fedorainfracloud.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo [following]
--2021-12-07 20:53:27-- https://copr.fedorainfracloud.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo
Resolving copr.fedorainfracloud.org (copr.fedorainfracloud.org)... 3.225.109.36, 2600:1f18:8ee:ae00:9d1f:4737:93ce:6db
Connecting to copr.fedorainfracloud.org (copr.fedorainfracloud.org)|3.225.109.36|:443... connected.
WARNING: cannot verify copr.fedorainfracloud.org's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
Issued certificate has expired.
HTTP request sent, awaiting response... 200 OK
Length: 376 [text/plain]
Saving to: ‘/etc/yum.repos.d/devtoolset-3.repo’
100%[=============================================>] 376 --.-K/s in 0s
2021-12-07 20:53:28 (49.6 MB/s) - ‘/etc/yum.repos.d/devtoolset-3.repo’ saved [376/376]
第2步:安装devtoolset-3-gcc
[root@localhost SPECS]# yum -y install devtoolset-3-gcc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.compevo.com
* centos-sclo-rh: mirrors.163.com
* centos-sclo-sclo: mirrors.163.com
* elrepo: mirror.rackspace.com
* extras: repos.lax.quadranet.com
* updates: linux.mirrors.es.net
Resolving Dependencies
--> Running transaction check
---> Package devtoolset-3-gcc.x86_64 0:4.9.2-6.el6 will be installed
--> Processing Dependency: devtoolset-3-binutils >= 2.22.52.0.1 for package: devtoolset-3-gcc-4.9.2-6.el6.x86_64
--> Processing Dependency: devtoolset-3-runtime for package: devtoolset-3-gcc-4.9.2-6.el6.x86_64
--> Processing Dependency: libgmp.so.3()(64bit) for package: devtoolset-3-gcc-4.9.2-6.el6.x86_64
--> Processing Dependency: libmpfr.so.1()(64bit) for package: devtoolset-3-gcc-4.9.2-6.el6.x86_64
--> Running transaction check
---> Package devtoolset-3-binutils.x86_64 0:2.24-18.el6 will be installed
---> Package devtoolset-3-gcc.x86_64 0:4.9.2-6.el6 will be installed
--> Processing Dependency: libgmp.so.3()(64bit) for package: devtoolset-3-gcc-4.9.2-6.el6.x86_64
--> Processing Dependency: libmpfr.so.1()(64bit) for package: devtoolset-3-gcc-4.9.2-6.el6.x86_64
---> Package devtoolset-3-runtime.x86_64 0:3.1-12.el6 will be installed
--> Finished Dependency Resolution
Error: Package: devtoolset-3-gcc-4.9.2-6.el6.x86_64 (copr:copr.fedorainfracloud.org:rhscl:devtoolset-3)
Requires: libmpfr.so.1()(64bit)
Error: Package: devtoolset-3-gcc-4.9.2-6.el6.x86_64 (copr:copr.fedorainfracloud.org:rhscl:devtoolset-3)
Requires: libgmp.so.3()(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
若第2步报错,缺少两个安装包,执行第3步:
安装依赖包libmpfr.so.1和libgmp.so.3,下载链接如下:
mpfr:
链接:https://pan.baidu.com/s/1_adAchU_VGmEbSGRoMnhGg
提取码:1234
gmp:
链接:https://pan.baidu.com/s/1nA-LAjArEAGhWSFHTBj0og
提取码:1234
第4步,安装缺省包:
下载后,使用命令安装即可:
yum install compat-libmpfr-2.4.1-1.sl7.x86_64.rpm
yum install compat-libgmp-4.3.1-1.sl7.x86_64.rpm
第5步,再次安装devtoolset-3-gcc
[root@localhost w0412]# yum install devtoolset-3-gcc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* centos-sclo-rh: mirrors.163.com
* centos-sclo-sclo: mirrors.163.com
* elrepo: mirror.rackspace.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package devtoolset-3-gcc.x86_64 0:4.9.2-6.el6 will be installed
--> Processing Dependency: devtoolset-3-binutils >= 2.22.52.0.1 for package: devtoolset-3-gcc-4.9.2-6.el6.x86_64
--> Processing Dependency: devtoolset-3-runtime for package: devtoolset-3-gcc-4.9.2-6.el6.x86_64
--> Running transaction check
---> Package devtoolset-3-binutils.x86_64 0:2.24-18.el6 will be installed
---> Package devtoolset-3-runtime.x86_64 0:3.1-12.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================
Package Arch Version Repository Size
=======================================================================================
Installing:
devtoolset-3-gcc
x86_64 4.9.2-6.el6 copr:copr.fedorainfracloud.org:rhscl:devtoolset-3 24 M
Installing for dependencies:
devtoolset-3-binutils
x86_64 2.24-18.el6 copr:copr.fedorainfracloud.org:rhscl:devtoolset-3 5.1 M
devtoolset-3-runtime
x86_64 3.1-12.el6 copr:copr.fedorainfracloud.org:rhscl:devtoolset-3 1.1 M
Transaction Summary
=======================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 30 M
Installed size: 69 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/copr:copr.fedorainfracloud.org:rhscl:devtoolset-3/packages/devtoolset-3-binutils-2.24-18.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 094d442c: NOKEY
Public key for devtoolset-3-binutils-2.24-18.el6.x86_64.rpm is not installed
(1/3): devtoolset-3-binutils-2.24-18.el6.x86_64.rpm | 5.1 MB 00:00:06
(2/3): devtoolset-3-runtime-3.1-12.el6.x86_64.rpm | 1.1 MB 00:00:01
(3/3): devtoolset-3-gcc-4.9.2-6.el6.x86_64.rpm | 24 MB 00:00:13
---------------------------------------------------------------------------------------
Total 2.2 MB/s | 30 MB 00:13
Retrieving key from https://download.copr.fedorainfracloud.org/results/rhscl/devtoolset-3/pubkey.gpg
Importing GPG key 0x094D442C:
Userid : "rhscl_devtoolset-3 (None)
Fingerprint: 143e 840e c0d0 ad21 e646 cdd8 fbce 6502 094d 442c
From : https://download.copr.fedorainfracloud.org/results/rhscl/devtoolset-3/pubkey.gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : devtoolset-3-runtime-3.1-12.el6.x86_64 1/3
Installing : devtoolset-3-binutils-2.24-18.el6.x86_64 2/3
Installing : devtoolset-3-gcc-4.9.2-6.el6.x86_64 3/3
Verifying : devtoolset-3-binutils-2.24-18.el6.x86_64 1/3
Verifying : devtoolset-3-runtime-3.1-12.el6.x86_64 2/3
Verifying : devtoolset-3-gcc-4.9.2-6.el6.x86_64 3/3
Installed:
devtoolset-3-gcc.x86_64 0:4.9.2-6.el6
Dependency Installed:
devtoolset-3-binutils.x86_64 0:2.24-18.el6 devtoolset-3-runtime.x86_64 0:3.1-12.el6
Complete!
第6步,安装devtoolset-3-gcc-c++
[root@localhost w0412]# yum install devtoolset-3-gcc-c++
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* centos-sclo-rh: mirrors.163.com
* centos-sclo-sclo: mirrors.163.com
* elrepo: mirror.rackspace.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package devtoolset-3-gcc-c++.x86_64 0:4.9.2-6.el6 will be installed
--> Processing Dependency: devtoolset-3-libstdc++-devel = 4.9.2-6.el6 for package: devtoolset-3-gcc-c++-4.9.2-6.el6.x86_64
--> Running transaction check
---> Package devtoolset-3-libstdc++-devel.x86_64 0:4.9.2-6.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================
Package Arch Version Repository Size
=======================================================================================
Installing:
devtoolset-3-gcc-c++
x86_64 4.9.2-6.el6 copr:copr.fedorainfracloud.org:rhscl:devtoolset-3 8.4 M
Installing for dependencies:
devtoolset-3-libstdc++-devel
x86_64 4.9.2-6.el6 copr:copr.fedorainfracloud.org:rhscl:devtoolset-3 2.0 M
Transaction Summary
=======================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 10 M
Installed size: 32 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): devtoolset-3-libstdc++-devel-4.9.2-6.el6.x86_64.rpm | 2.0 MB 00:00:18
(2/2): devtoolset-3-gcc-c++-4.9.2-6.el6.x86_64.rpm | 8.4 MB 00:00:19
---------------------------------------------------------------------------------------
Total 534 kB/s | 10 MB 00:19
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : devtoolset-3-libstdc++-devel-4.9.2-6.el6.x86_64 1/2
Installing : devtoolset-3-gcc-c++-4.9.2-6.el6.x86_64 2/2
Verifying : devtoolset-3-gcc-c++-4.9.2-6.el6.x86_64 1/2
Verifying : devtoolset-3-libstdc++-devel-4.9.2-6.el6.x86_64 2/2
Installed:
devtoolset-3-gcc-c++.x86_64 0:4.9.2-6.el6
Dependency Installed:
devtoolset-3-libstdc++-devel.x86_64 0:4.9.2-6.el6
Complete!
第7步,安装devtoolset-3-binutils
[root@localhost w0412]# yum install devtoolset-3-binutils
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* centos-sclo-rh: mirrors.163.com
* centos-sclo-sclo: mirrors.163.com
* elrepo: mirror.rackspace.com
* extras: mirrors.163.com
第8步,设置当前gcc版本:
scl enable devtoolset-3 bash
或
source /opt/rh/devtoolset-3/enable
第9步,查看gcc版本
[root@localhost w0412]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-3/root/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/opt/rh/devtoolset-3/root/usr --mandir=/opt/rh/devtoolset-3/root/usr/share/man --infodir=/opt/rh/devtoolset-3/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,fortran,lto --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/cloog-install --with-mpc=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/mpc-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.9.2 20150212 (Red Hat 4.9.2-6) (GCC)
至此,升级gcc完成。