linux 中升级gcc版本

 

001、发行版信息

[root@pc1 test]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)    ## centos7.6

 

002、当前gcc版本

[root@pc1 test]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@pc1 test]# g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

003、安装 centos-release-scl

[root@pc1 test]# yum install centos-release-scl

 

004、查找所有的可安装devtoolset 版本

[root@pc1 test]# yum list devtoolset-*     ## 查看结果显示可安装的最高版本为11

 

005、安装devtoolset 11版本

[root@pc1 test]# yum install devtoolset-11*    ## 安装11版本

 

006、激活对应的devtoolset,所以你可以一次安装多个版本的devtoolset

[root@pc1 test]# scl enable devtoolset-11 bash

 

007、查看此时的版本

(base) [root@pc1 test]# gcc --version
gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

(base) [root@pc1 test]# g++ --version
g++ (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

008、11版本的安装目录在:安装的8版本gcc在系统 /opt/rh目录下,启动该版本需执行 ./enable

 

009、 永久生效:

(base) [root@pc1 test]# mv /usr/bin/gcc /usr/bin/gcc-4.8.5
(base) [root@pc1 test]# ln -s /opt/rh/devtoolset-11/root/usr/bin/gcc /usr/bin/gcc
(base) [root@pc1 test]# mv /usr/bin/g++ /usr/bin/g++-4.8.5
(base) [root@pc1 test]# ln -s /opt/rh/devtoolset-11/root/usr/bin/g++ /usr/bin/g++

 

参考:

01、https://www.cnblogs.com/wangcr/p/15828437.html

 

posted @ 2023-11-03 22:34  小鲨鱼2018  阅读(173)  评论(0编辑  收藏  举报