ubuntu18.04安装gcc及切换gcc版本

分割线前半部分参考:https://blog.csdn.net/CAU_Ayao/article/details/83987120
首先查看自己的gcc版本,Ubuntu18.04上默认的是7.3版本

gcc --version
gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright © 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.

  1. 下载gcc/g++ 5
    sudo apt-get install -y gcc-5
    sudo apt-get install -y g++ -5

  2. 链接gcc/g++实现降级

cd /usr/bin
sudo rm gcc
sudo ln -s gcc-5 gcc
sudo rm g++
suds ln -s g++ -5 g++

再次查看gcc版本,可以看到已经降级.

gcc --version
gcc (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010
Copyright © 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.

分割线
————————————————
在试了上述方法后,我的gcc版本号还是没更改过来,于是:
通过命令行:
z840@z840-HP-Z840-Workstation:~$ which gcc
/usr/local/cuda-9.0/bin/gcc

z840@z840-HP-Z840-Workstation:/usr/bin$ cd /usr/local/cuda-9.0/bin
z840@z840-HP-Z840-Workstation:/usr/local/cuda-9.0/bin$ ls
g++ nvprof
cudafe gcc nvprune

z840@z840-HP-Z840-Workstation:/usr/local/cuda-9.0/bin$ ll
total 65252
drwxr-xr-x 3 root root 4096 Nov 16 16:54 ./
lrwxrwxrwx 1 root root 14 Nov 16 16:54 g++ -> /usr/bin/g+±7*
lrwxrwxrwx 1 root root 14 Nov 16 16:54 gcc -> /usr/bin/gcc-7*

发现g++,gcc软连接未更改,删掉软连接,重新建立对应版本号的软连接5
eg.
suds ln -s /usr/bin/g+±5 g++
suds ln -s /usr/bin/gcc-5 gcc

你可能感兴趣的:(ubuntu18.04安装gcc及切换gcc版本)