1、Centos7官方源的gcc最新版本是4.8.5,升级版本以安装源方式
2、源安装
# 系统查看
[root@localhost software]# hostnamectl
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: beef83b85f57437282ac778c4db38025
Boot ID: 084ecb17504d4e2abae4b265a2c55b8d
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1062.el7.x86_64
Architecture: x86-64
# 系统
[root@localhost software]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
# 安装
[root@localhost software]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* centos-sclo-rh: mirrors.qlu.edu.cn
* centos-sclo-sclo: mirrors.qlu.edu.cn
* epel: mirror-hnd.misakamikoto.network
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
repo id repo name status
!base/7/x86_64 CentOS-7 - Base 10,072
centos-sclo-rh/x86_64 CentOS-7 - SCLo rh 8,170
centos-sclo-sclo/x86_64 CentOS-7 - SCLo sclo 816
!epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,785
!extras/7/x86_64 CentOS-7 - Extras 515
!mysql-connectors-community/x86_64 MySQL Connectors Community 220
!mysql-tools-community/x86_64 MySQL Tools Community 98
!mysql57-community/x86_64 MySQL 5.7 Community Server 660
!nginx/x86_64 nginx repo 316
!updates/7/x86_64 CentOS-7 - Updates 4,926
repolist: 39,578
# gcc版本
[root@localhost software]# yum list |grep devtoolset |grep gcc.x86_64
devtoolset-10-gcc.x86_64 10.2.1-11.2.el7 @centos-sclo-rh
devtoolset-11-gcc.x86_64 11.2.1-9.1.el7 @centos-sclo-rh
devtoolset-7-gcc.x86_64 7.3.1-5.16.el7 @centos-sclo-rh
devtoolset-8-gcc.x86_64 8.3.1-3.2.el7 @centos-sclo-rh
devtoolset-11-annobin-plugin-gcc.x86_64 10.38-1.el7 centos-sclo-rh
devtoolset-9-gcc.x86_64 9.3.1-2.2.el7 centos-sclo-rh
# gcc版本
[root@localhost software]# yum --disablerepo="*" --enablerepo="centos-sclo-rh" list available |grep gcc.x86_64
devtoolset-11-annobin-plugin-gcc.x86_64 10.38-1.el7 centos-sclo-rh
devtoolset-9-gcc.x86_64 9.3.1-2.2.el7 centos-sclo-rh
3、gcc多个软件版本可以同时安装,相互之间不会覆盖和冲突,也不会覆盖系统的版本。
即系统可以同时存在gcc10, gcc11等多个版本。
安装10版本:
[root@localhost software]# yum -y install devtoolset-10-gcc devtoolset-10-gcc-c++
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 7.4 kB 00:00:00
* base: ftp.sjtu.edu.cn
* centos-sclo-rh: mirrors.qlu.edu.cn
* centos-sclo-sclo: mirrors.qlu.edu.cn
* epel: mirror-icn.misakamikoto.network
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
mysql-connectors-community | 2.6 kB 00:00:00
mysql-tools-community | 2.6 kB 00:00:00
mysql57-community | 2.6 kB 00:00:00
nginx | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Package devtoolset-10-gcc-10.2.1-11.2.el7.x86_64 already installed and latest version
Package devtoolset-10-gcc-c++-10.2.1-11.2.el7.x86_64 already installed and latest version
Nothing to do
4、查看安装路径
# 查询安装
[root@localhost software]# rpm -qa |grep devtoolset
devtoolset-11-binutils-2.36.1-1.el7.2.x86_64
devtoolset-8-runtime-8.1-1.el7.x86_64
devtoolset-11-gcc-c++-11.2.1-9.1.el7.x86_64
devtoolset-10-gcc-10.2.1-11.2.el7.x86_64
devtoolset-7-libstdc++-devel-7.3.1-5.16.el7.x86_64
devtoolset-10-gcc-c++-10.2.1-11.2.el7.x86_64
devtoolset-8-gcc-c++-8.3.1-3.2.el7.x86_64
devtoolset-11-runtime-11.1-2.el7.x86_64
devtoolset-10-binutils-2.35-5.el7.4.x86_64
devtoolset-7-gcc-c++-7.3.1-5.16.el7.x86_64
devtoolset-8-libstdc++-devel-8.3.1-3.2.el7.x86_64
devtoolset-8-gcc-8.3.1-3.2.el7.x86_64
devtoolset-10-libstdc++-devel-10.2.1-11.2.el7.x86_64
devtoolset-7-runtime-7.1-4.el7.x86_64
devtoolset-8-binutils-2.30-55.el7.2.x86_64
devtoolset-11-libstdc++-devel-11.2.1-9.1.el7.x86_64
devtoolset-10-runtime-10.1-0.el7.x86_64
devtoolset-7-gcc-7.3.1-5.16.el7.x86_64
devtoolset-7-binutils-2.28-11.el7.x86_64
devtoolset-11-gcc-11.2.1-9.1.el7.x86_64
# 安装版本绝对路径
[root@localhost software]# rpm -ql devtoolset-10-gcc-10.2.1-11.2.el7.x86_64
/opt/rh/devtoolset-10/root/usr/bin/cc
/opt/rh/devtoolset-10/root/usr/bin/cpp
/opt/rh/devtoolset-10/root/usr/bin/gcc
/opt/rh/devtoolset-10/root/usr/bin/gcc-ar
/opt/rh/devtoolset-10/root/usr/bin/gcc-nm
/opt/rh/devtoolset-10/root/usr/bin/gcc-ranlib
/opt/rh/devtoolset-10/root/usr/bin/gcov
/opt/rh/devtoolset-10/root/usr/bin/gcov-dump
/opt/rh/devtoolset-10/root/usr/bin/gcov-tool
/opt/rh/devtoolset-10/root/usr/bin/i686-redhat-linux-gcc-10
4、在当前界面起作用,新开界面版本恢复最初版本
[root@localhost software]# source /opt/rh/devtoolset-10/enable
# 查看版本
[root@localhost software]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-10/root/usr --mandir=/opt/rh/devtoolset-10/root/usr/share/man --infodir=/opt/rh/devtoolset-10/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --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 --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-10.2.1-20210130/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.1 20210130 (Red Hat 10.2.1-11) (GCC)
[root@localhost software]#
4、永久使用此版本配置,添加到环境变量
vim /etc/profile
# 最后一行添加
export GCC_HOME=/opt/rh/devtoolset-10/root/usr
export PATH=${GCC_HOME}/bin:$PATH
# 退出保存
# 生效
source /etc/profile