美文网首页
ubuntu 18.0.4 降级安装gcc 5

ubuntu 18.0.4 降级安装gcc 5

作者: yanlong107 | 来源:发表于2022-02-09 15:58 被阅读0次

    背景

    项目当前使用的ubuntu版本是 18.04(如何查看当前linux版本见文章最后), 默认安装的gcc版本是7.5.0, 在这环境编译出来的deb包在银河麒麟v10 sp1系统上可以兼容,但是在银河麒麟v10 的OS上会出现兼容性的问(原因是银河麒麟v10上运行的deb需要使用gcc 5进行编译),因此需要在ubuntu 18.04版本上安装gcc 5 的版本

    降级安装gcc 5

    gcc 的安装有两种方式:
    1、通过apt 包管理器进行安装
    2、通过源码手动编译安装
    ps:linux上可以gcc多版本共存
    这里推荐使用第一种方式安装, 源码编译出错,需要安装一系列的依赖,比较复杂。

    通过apt 包管理器进行安装

    • 直接安装gcc、g++ 5.4.0 版本,提示找不到版本
      ps:默认的软件源中不包含gcc 5.4.0 版本
    root@d8b6c26946f0:/workspace# apt-get install gcc-5.4.0                                                                               
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Unable to locate package gcc-5.4.0
    E: Couldn't find any package by glob 'gcc-5.4.0'
    E: Couldn't find any package by regex 'gcc-5.4.0'
    
    • sources.list 中添加软件源地址 deb http://cz.archive.ubuntu.com/ubuntu bionic main universe 其中cz.archive.ubuntu.com/ubuntu 可换成国内的镜像源
    // 我使用的软件源地址
    deb https://mirrors.cloud.tencent.com/ubuntu/ bionic main universe
    

    之后update,后重新instll

    root@d8b6c26946f0:/workspace# apt-get update
    root@d8b6c26946f0:/workspace# apt-get install -y gcc-5
    root@d8b6c26946f0:/workspace# apt-get install -y g++-5
    

    安装完成后,系统中会同时存在gcc5 和 gcc7,还需要删除原有gcc链接,重新建立软链接,这样在使用gcc的时候使用的就是gcc5的版本了

    • 查看本地gcc 情况
    root@d8b6c26946f0:/usr/bin# ll |grep gcc                                                                                                                   
    -rwxr-xr-x 1 root root        428 May  7  2006 c89-gcc*
    -rwxr-xr-x 1 root root        454 Apr 11  2011 c99-gcc*
    lrwxrwxrwx 1 root root          5 May 20  2019 gcc -> gcc-7*
    -rwxr-xr-x 1 root root     907648 Apr 11  2018 gcc-5*
    lrwxrwxrwx 1 root root         22 Dec  4  2019 gcc-7 -> x86_64-linux-gnu-gcc-7*
    lrwxrwxrwx 1 root root          8 May 20  2019 gcc-ar -> gcc-ar-7*
    -rwxr-xr-x 1 root root      31264 Apr 11  2018 gcc-ar-5*
    lrwxrwxrwx 1 root root         25 Dec  4  2019 gcc-ar-7 -> x86_64-linux-gnu-gcc-ar-7*
    lrwxrwxrwx 1 root root          8 May 20  2019 gcc-nm -> gcc-nm-7*
    -rwxr-xr-x 1 root root      31264 Apr 11  2018 gcc-nm-5*
    lrwxrwxrwx 1 root root         25 Dec  4  2019 gcc-nm-7 -> x86_64-linux-gnu-gcc-nm-7*
    lrwxrwxrwx 1 root root         12 May 20  2019 gcc-ranlib -> gcc-ranlib-7*
    -rwxr-xr-x 1 root root      31264 Apr 11  2018 gcc-ranlib-5*
    lrwxrwxrwx 1 root root         29 Dec  4  2019 gcc-ranlib-7 -> x86_64-linux-gnu-gcc-ranlib-7*
    -rwxr-xr-x 1 root root       2189 Nov 29  2019 gccmakedep*
    lrwxrwxrwx 1 root root          5 May 20  2019 x86_64-linux-gnu-gcc -> gcc-7*
    lrwxrwxrwx 1 root root          5 Apr 11  2018 x86_64-linux-gnu-gcc-5 -> gcc-5*
    -rwxr-xr-x 1 root root    1047488 Dec  4  2019 x86_64-linux-gnu-gcc-7*
    lrwxrwxrwx 1 root root          8 May 20  2019 x86_64-linux-gnu-gcc-ar -> gcc-ar-7*
    lrwxrwxrwx 1 root root          8 Apr 11  2018 x86_64-linux-gnu-gcc-ar-5 -> gcc-ar-5*
    -rwxr-xr-x 1 root root      31200 Dec  4  2019 x86_64-linux-gnu-gcc-ar-7*
    lrwxrwxrwx 1 root root          8 May 20  2019 x86_64-linux-gnu-gcc-nm -> gcc-nm-7*
    lrwxrwxrwx 1 root root          8 Apr 11  2018 x86_64-linux-gnu-gcc-nm-5 -> gcc-nm-5*
    -rwxr-xr-x 1 root root      31200 Dec  4  2019 x86_64-linux-gnu-gcc-nm-7*
    lrwxrwxrwx 1 root root         12 May 20  2019 x86_64-linux-gnu-gcc-ranlib -> gcc-ranlib-7*
    lrwxrwxrwx 1 root root         12 Apr 11  2018 x86_64-linux-gnu-gcc-ranlib-5 -> gcc-ranlib-5*
    -rwxr-xr-x 1 root root      31200 Dec  4  2019 x86_64-linux-gnu-gcc-ranlib-7*
    
    • 创建软链接 (gcc 重新升级到gcc7的话,重新创建这里的软链接就可以了)
    cd /usr/bin 
    sudo rm -r gcc //移除之前的软链接
    sudo ln -sf gcc-5 gcc // 建立gcc-5的软链接 此处尝试使用gcc-5.5.0,但是报错
    sudo rm -r g++  //同上
    sudo ln -sf g++-5 g++  //同上
    
    • 检查gcc 版本
    root@d8b6c26946f0:/usr/bin# gcc -v                                                                                                                         
    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.5.0-12ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
    Thread model: posix
    gcc version 5.5.0 20171010 (Ubuntu 5.5.0-12ubuntu1) 
    

    相关Linux命令

    1、查看ubuntu 版本 lsb_release -a

    root@d8b6c26946f0:/# lsb_release -a                                                                                                                        
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 18.04.4 LTS
    Release:        18.04
    Codename:       bionic
    

    2、 查看当前系统使用的内核版本: uname -r

    root@d8b6c26946f0:/# uname -r                                                                                                                              
    3.10.107-1-tlinux2_kvm_guest-0049
    

    3、查看gcc版本:gcc --version

    root@d8b6c26946f0:/# gcc --version                                                                                                                         
    gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
    Copyright (C) 2017 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.
    

    4、当前ubuntu 使用的镜像源(使用的腾讯云镜像源):cat /etc/apt/sources.list

    root@d8b6c26946f0:/# cat /etc/apt/sources.list                                                                                                             
    deb https://mirrors.cloud.tencent.com/ubuntu/ focal main restricted universe multiverse
    deb-src https://mirrors.cloud.tencent.com/ubuntu/ focal main restricted universe multiverse
    
    deb https://mirrors.cloud.tencent.com/ubuntu/ focal-security main restricted universe multiverse
    deb-src https://mirrors.cloud.tencent.com/ubuntu/ focal-security main restricted universe multiverse
    
    deb https://mirrors.cloud.tencent.com/ubuntu/ focal-updates main restricted universe multiverse
    deb-src https://mirrors.cloud.tencent.com/ubuntu/ focal-updates main restricted universe multiverse
    
    deb https://mirrors.cloud.tencent.com/ubuntu/ focal-backports main restricted universe multiverse
    deb-src https://mirrors.cloud.tencent.com/ubuntu/ focal-backports main restricted universe multiverse
    
    ## Not recommended
    # deb https://mirrors.cloud.tencent.com/ubuntu/ focal-proposed main restricted universe multiverse
    # deb-src https://mirrors.cloud.tencent.com/ubuntu/ focal-proposed main restricted universe multiverse
    

    参考文章:https://packages.ubuntu.com/bionic/amd64/gcc-5/download

    相关文章

      网友评论

          本文标题:ubuntu 18.0.4 降级安装gcc 5

          本文链接:https://www.haomeiwen.com/subject/ogqikrtx.html