centos通过yum升级gcc/g++版本4/5/7/8/9

xingyun86 2019-11-18 1446

如果是centos8,则:

How do I install static versions of glibc on CentOS 8

Note : glibc-static、libstdc++-static is in this repo: /etc/yum.repos.d/CentOS-PowerTools.repo

# dnf config-manager --enable PowerTools

Package list, "PowerTools" http://mirror.centos.org/centos/8/PowerTools/x86_64/os/Packages/
Example mirror, "PowerTools" http://mirror.centos.org/centos/8/PowerTools/x86_64/os/

# dnf search glibc
# dnf provides */libc.a
         // both commands will (also) reply: glibc-static
# dnf install glibc-static
# dnf install libstdc++-static

安装静态gcc开发库:

# centos
sudo yum install glibc-static
# ubuntu
sudo apt-get install libc6-dev

CMake配置:
# 静态链接
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")

gcc 4.8 安装

[root@DS-VM-Node239 ~]# curl -Lks http://www.hop5.in/yum/el6/hop5.repo > /etc/yum.repos.d/hop5.repo
[root@DS-VM-Node239 ~]# yum install gcc gcc-g++ -y
[root@DS-VM-Node239 ~]# gcc --version
gcc (GCC) 4.8.2 20131212 (Red Hat 4.8.2-8)
Copyright © 2013 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
[root@DS-VM-Node239 ~]# g++ --version
g++ (GCC) 4.8.2 20131212 (Red Hat 4.8.2-8)
Copyright © 2013 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
[root@DS-VM-Node211 ~]#

gcc 4.9 安装

[root@DS-VM-Node239 ~]# yum install centos-release-scl -y
[root@DS-VM-Node239 ~]# yum install devtoolset-3-toolchain -y
[root@DS-VM-Node239 ~]# scl enable devtoolset-3 bash
[root@DS-VM-Node239 ~]# gcc --version
gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
Copyright (C) 2014 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@DS-VM-Node239 ~]# g++ --version
g++ (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
Copyright (C) 2014 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@DS-VM-Node239 ~]# gfortran --version
GNU Fortran (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
Copyright (C) 2014 Free Software Foundation, Inc.
 
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
 
[root@DS-VM-Node239 ~]#

gcc 5.2 安装

[root@DS-VM-Node239 ~]# yum install centos-release-scl -y
[root@DS-VM-Node239 ~]# yum install devtoolset-4-toolchain -y
[root@DS-VM-Node239 ~]# scl enable devtoolset-4 bash
[root@DS-VM-Node239 ~]# gcc --version
gcc (GCC) 5.2.1 20150902 (Red Hat 5.2.1-2)
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@DS-VM-Node239 ~]# g++ --version
g++ (GCC) 5.2.1 20150902 (Red Hat 5.2.1-2)
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@DS-VM-Node239 ~]#

gcc 8.3 安装

[root@DS-VM-Node239 ~]# yum install centos-release-scl -y
[root@DS-VM-Node239 ~]# yum install devtoolset-8-toolchain -y
[root@DS-VM-Node239 ~]# scl enable devtoolset-8 bash
[root@DS-VM-Node239 ~]# gcc --version
gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
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@DS-VM-Node239 ~]# g++ --version
g++ (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
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@DS-VM-Node239 ~]#

gcc 9 安装

[root@DS-VM-Node239 ~]# yum install centos-release-scl -y
[root@DS-VM-Node239 ~]# yum install devtoolset-9-toolchain -y
[root@DS-VM-Node239 ~]# scl enable devtoolset-9 bash
[root@DS-VM-Node239 ~]# gcc --version
gcc (GCC) 9.1.1 20190605 (Red Hat 9.1.1-2)
Copyright (C) 2019 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@DS-VM-Node239 ~]# g++ --version
g++ (GCC) 9.1.1 20190605 (Red Hat 9.1.1-2)
Copyright (C) 2019 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@DS-VM-Node239 ~]#

gcc 11 安装

[root@DS-VM-Node239 ~]# yum install centos-release-scl -y
[root@DS-VM-Node239 ~]# yum install devtoolset-11-toolchain -y
[root@DS-VM-Node239 ~]# scl enable devtoolset-11 bash
[root@DS-VM-Node239 ~]# gcc --version
gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)
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.
 
[root@DS-VM-Node239 ~]# g++ --version
g++ (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)
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.
 
[root@DS-VM-Node239 ~]#


如果需要临时使用gcc新版本的话,则执行一下命令即可:
scl enable devtoolset-9 bash
gcc --version


如果需要永久重启gcc版本是新版本的话,可通过输入命令切换为新版本(两条命令均可)

vi ~/.bashrc末尾新增两行:

source /opt/rh/devtoolset-9/enable
source scl_source enable devtoolset-9
gcc --version

卸载:

scl -l
sudo yum remove devtoolset-8\*


×
打赏作者
最新回复 (0)
查看全部
全部楼主
返回