当前位置:   article > 正文

Ubuntu18.04 系统离线升级gcc、g++_ubuntu18.04离线安装gcc

ubuntu18.04离线安装gcc

本人当前的ubuntu18.04的gcc版本是7.5.0,在项目中有些库和功能需要使用更高版本的gcc,因此需要升级gcc至9.4.0,并与原来的老版本共存。由于工作电脑无法联网,因此采用离线安装的方式。

安装过程参考博客1博客2

1、下载对应版本的安装包

gcc下载地址:http://ftp.gnu.org/gnu/gcc/,这里我选择的是gcc-9.4.0.tar.gz。

http://ftp.gnu.org/gnu/gcc/

2、下载对应版本的依赖库的安装包:mpfr-3.1.4.tar.bz2、gmp-6.1.0.tar.bz2、mpc-1.0.3.tar.gz、isl-0.18.tar.bz2。
gmp:http://ftp.gnu.org/pub/gnu/gmp/
mpfr:https://mirrors.sjtug.sjtu.edu.cn/gnu/mpfr/
mpc:http://ftp.gnu.org/gnu/mpc/
isl :http://www.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/

3、解压文件

使用mv命令将gcc-9.4.0.tar.gz移动到目录’/usr/local/ '中,并解压文件。

将依赖的四个gmp、mpfr、mpc、isl包移动到 /usr/local/gcc-9.4.0目录下并解压。

建立软连接:

  1. ln -sf gmp-6.1.0 gmp
  2. ln -sf mpfr-3.1.4 mpfr
  3. ln -sf mpc-1.0.3 mpc
  4. ln -sf isl-0.18 isl

4、安装gcc,编译时间较久...

  1. cd /usr/local/gcc-9.4.0
  2. mkdir build
  3. cd build
  4. ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
  5. make -j8
  6. make install

5、查看版本

  1. ls /usr/bin/gcc*
  2. ls /usr/bin/g++*

6、手动切换运行版本,并将需要的版本添加到 update-alternatives 中,设置优先级

  1. #gcc
  2. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 30
  3. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 40
  4. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100
  5. #g++
  6. sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 40
  7. sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50
  8. sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 100

7、手动配置 update-alternatives

  1. sudo update-alternatives --config gcc
  2. sudo update-alternatives --config g++

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/940340
推荐阅读
相关标签
  

闽ICP备14008679号