zoukankan      html  css  js  c++  java
  • Centos6安装gcc4.8及以上版本

    很多场景我们编译C源码,都需要使用gcc4.8及以上版本,比如编译MySQL 8.0、GRPC等,原因是需要支持C++11。但CentOS 6其内置版本是gcc4.4。

    使用gcc --version可以查看版本。

    $gcc --version
    gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
    

    源码编译

    常规升级办法是:
    1、下载gcc新版本;
    2、编译。

    但gcc编译起来真的是非常非常的慢,而且特别耗资源,编译到后面选择放弃了(ps:编译的机器配置不高)。后来发现了devtoolset这个工具,几分钟就搞定了gcc版本升级的问题。

    使用scl+devtoolset

    使用devtoolset后gcc的升级流程是:
    1、安装SCL源;
    2、安装devtoolset工具集;
    3、使用scl命令启用工具集。

    注:建议安装devtoolset-6(devtoolset-6目前gcc版本为6.3)及以上版本,因为devtoolset-4及之前的版本都已经结束支持,只能通过增加源方法安装。

    升级到gcc 8

    yum -y install centos-release-scl
    yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
    scl enable devtoolset-8 bash
    

    下面是安装过程的部分输出:

    Installing:
     devtoolset-8-binutils          x86_64   2.30-55.el6.1   centos-sclo-rh   6.0 M
     devtoolset-8-gcc               x86_64   8.3.1-3.1.el6   centos-sclo-rh    32 M
     devtoolset-8-gcc-c++           x86_64   8.3.1-3.1.el6   centos-sclo-rh    12 M
    Installing for dependencies:
     devtoolset-8-libstdc++-devel   x86_64   8.3.1-3.1.el6   centos-sclo-rh   2.9 M
     devtoolset-8-runtime           x86_64   8.1-1.el6       centos-sclo-rh   1.0 M
    
    Transaction Summary
    ================================================================================
    Install       5 Package(s)
    
    Total download size: 54 M
    Installed size: 141 M
    

    查看版本:

    $ gcc --version
    gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
    

    需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。如果要长期使用gcc 8的话:

    echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile
    

    这样退出shell重新打开就是新版的gcc了。其它版本同理。

    上面安装devtoolset的时候指定仅安装gccgcc-c++binutils,如果仅写yum -y install devtoolset-8则会下载所有相关工具,会包含:

    Installing:
     devtoolset-8                   x86_64 8.1-1.el6           centos-sclo-rh 5.4 k
    Installing for dependencies:
     avahi-libs                     x86_64 0.6.25-17.el6       base            55 k
     devtoolset-8-dwz               x86_64 0.12-1.1.el6        centos-sclo-rh  95 k
     devtoolset-8-dyninst           x86_64 9.3.2-6.el6         centos-sclo-rh 3.5 M
     devtoolset-8-elfutils          x86_64 0.176-1.el6         centos-sclo-rh 406 k
     devtoolset-8-elfutils-libelf   x86_64 0.176-1.el6         centos-sclo-rh 200 k
     devtoolset-8-elfutils-libs     x86_64 0.176-1.el6         centos-sclo-rh 297 k
     devtoolset-8-gcc-gfortran      x86_64 8.3.1-3.1.el6       centos-sclo-rh  12 M
     devtoolset-8-gdb               x86_64 8.2-3.el6           centos-sclo-rh 3.3 M
     devtoolset-8-libquadmath-devel x86_64 8.3.1-3.1.el6       centos-sclo-rh 156 k
     devtoolset-8-ltrace            x86_64 0.7.91-1.el6        centos-sclo-rh 133 k
     devtoolset-8-make              x86_64 1:4.2.1-4.el6       centos-sclo-rh 484 k
     devtoolset-8-memstomp          x86_64 0.1.5-5.el6         centos-sclo-rh 340 k
     devtoolset-8-oprofile          x86_64 1.3.0-2.el6         centos-sclo-rh 2.7 M
     devtoolset-8-perftools         x86_64 8.1-1.el6           centos-sclo-rh 2.8 k
     devtoolset-8-strace            x86_64 4.24-2.el6          centos-sclo-rh 988 k
     devtoolset-8-systemtap         x86_64 3.3-1.el6           centos-sclo-rh 144 k
     devtoolset-8-systemtap-client  x86_64 3.3-1.el6           centos-sclo-rh 2.8 M
     devtoolset-8-systemtap-devel   x86_64 3.3-1.el6           centos-sclo-rh 2.2 M
     devtoolset-8-systemtap-runtime x86_64 3.3-1.el6           centos-sclo-rh 406 k
     devtoolset-8-toolchain         x86_64 8.1-1.el6           centos-sclo-rh 3.0 k
     devtoolset-8-valgrind          x86_64 1:3.14.0-16.el6     centos-sclo-rh  11 M
     json-c                         x86_64 0.11-13.el6         base            27 k
     kernel-debug-devel             x86_64 2.6.32-754.28.1.el6 updates         11 M
     libgfortran5                   x86_64 8.2.1-1.3.1.el6_10  updates        678 k
     libquadmath                    x86_64 8.2.1-1.3.1.el6_10  updates        160 k
     zip                            x86_64 3.0-1.el6_7.1       base           259 k
    
    Transaction Summary
    ================================================================================
    Install      27 Package(s)
    
    Total download size: 53 M
    Installed size: 152 M
    

    升级到gcc 7.3

    yum -y install centos-release-scl
    yum -y install devtoolset-7-gcc devtoolset-7-gcc-c++ devtoolset-7-binutils
    scl enable devtoolset-7 bash
    

    升级到gcc 6.3

    yum -y install centos-release-scl
    # install gcc gcc-c++
    yum -y install devtoolset-6-gcc devtoolset-6-gcc-c++ devtoolset-6-binutils
    scl enable devtoolset-6 bash
    

    升级到gcc 5.2

    wget https://copr.fedoraproject.org/coprs/hhorak/devtoolset-4-rebuild-bootstrap/repo/epel-6/hhorak-devtoolset-4-rebuild-bootstrap-epel-6.repo -O /etc/yum.repos.d/devtoolset-4.repo
    yum install devtoolset-4-gcc devtoolset-4-gcc-c++ devtoolset-4-binutils -y
    scl enable devtoolset-4 bash
    

    已经停止支持的devtoolset4及之前版本的安装方法,可能比较慢。

    升级到gcc 4.9

    wget 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
    yum -y install devtoolset-3-gcc devtoolset-3-gcc-c++ devtoolset-3-binutils
    scl enable devtoolset-3 bash
    

    升级到gcc 4.8

    wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtoolset-2.repo
    yum -y install devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils
    scl enable devtoolset-2 bash
    

    参考

    1、为CentOS 6、7升级gcc至4.8、4.9、5.2、6.3、7.3等高版本
    http://www.vpser.net/manage/centos-6-upgrade-gcc.html
    2、CentOS 下安装高版本 GCC - 运维之美
    https://www.hi-linux.com/posts/25767.html
    3、Developer Toolset 8 — Software Collections
    https://www.softwarecollections.org/en/scls/rhscl/devtoolset-8/
    4、Product Documentation for Red Hat Developer Toolset 9 - Red Hat Customer Portal
    https://access.redhat.com/documentation/en-us/Red_Hat_Developer_Toolset/9/

  • 相关阅读:
    第十章 系统级I/O
    第九章 虚拟内存
    第六章 存储器层次结构
    第八章 异常控制流(下)
    第八章 异常控制流(上)
    第三章 机器的程序级表示(下)
    第三章 机器的程序级表示(中)
    第三章 机器的程序级表示(上)
    python学习之列表的定义以及增删改查
    Python学习之字符串中的下标和切片以及逆序
  • 原文地址:https://www.cnblogs.com/52fhy/p/12547521.html
Copyright © 2011-2022 走看看