软连接来实现
因为服务器上的gcc版本比较旧,但自己又没有sudo权限,所以通过修改软连接的方法来更改自己环境里的gcc版本(同时也不会影响到服务器上的其他人)
这个工作的前提是服务器上装有多个版本的gcc。
#可以看到原始路径里有这些路径
# yh @ deepserver3 in ~/SMAP/extensions [1:50:22]
$ echo $PATH
/home/yh/anaconda3/envs/SMAP/bin:/home/yh/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/cuda/bin:/home/yh/anaconda3/bin
修改zshrc文件
# yh @ deepserver3 in ~/SMAP/extensions [1:50:27]
$ vim ~/.zshrc
这个路径的写法有一个需要注意的地方,由于新加入的路径里存在需要提前加载的gcc,所以要将新加入的路径写在之前的PATH之前,也就是¥HOME/.local/bin:$PATH
保存(加载zsh里面的语句)
# yh @ deepserver3 in ~/SMAP/extensions [1:53:15]
$ zsh
我们看到现在的路径里已经新加了这么一条路径
# yh @ deepserver3 in ~/SMAP/extensions [1:53:20]
$ echo $PATH
/home/yh/.local/bin:/home/yh/anaconda3/envs/SMAP/bin:/home/yh/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/cuda/bin:/home/yh/anaconda3/bin:/usr/local/cuda/bin:/home/yh/anaconda3/bin
我们需要将gcc5升级到gcc6,查看gcc的安装位置
# yh @ deepserver3 in ~/SMAP/extensions [1:48:35]
$ ll /usr/bin/gcc*
lrwxrwxrwx 1 root root 5 Nov 4 2020 /usr/bin/gcc -> gcc-5
-rwxr-xr-x 1 root root 887K Apr 11 2018 /usr/bin/gcc-5
lrwxrwxrwx 1 root root 22 Nov 12 2018 /usr/bin/gcc-6 -> x86_64-linux-gnu-gcc-6
lrwxrwxrwx 1 root root 22 Dec 4 2019 /usr/bin/gcc-7 -> x86_64-linux-gnu-gcc-7
lrwxrwxrwx 1 root root 8 May 20 2019 /usr/bin/gcc-ar -> gcc-ar-7
-rwxr-xr-x 1 root root 31K Apr 11 2018 /usr/bin/gcc-ar-5
lrwxrwxrwx 1 root root 25 Nov 12 2018 /usr/bin/gcc-ar-6 -> x86_64-linux-gnu-gcc-ar-6
lrwxrwxrwx 1 root root 25 Dec 4 2019 /usr/bin/gcc-ar-7 -> x86_64-linux-gnu-gcc-ar-7
lrwxrwxrwx 1 root root 8 May 20 2019 /usr/bin/gcc-nm -> gcc-nm-7
-rwxr-xr-x 1 root root 31K Apr 11 2018 /usr/bin/gcc-nm-5
lrwxrwxrwx 1 root root 25 Nov 12 2018 /usr/bin/gcc-nm-6 -> x86_64-linux-gnu-gcc-nm-6
lrwxrwxrwx 1 root root 25 Dec 4 2019 /usr/bin/gcc-nm-7 -> x86_64-linux-gnu-gcc-nm-7
lrwxrwxrwx 1 root root 12 May 20 2019 /usr/bin/gcc-ranlib -> gcc-ranlib-7
-rwxr-xr-x 1 root root 31K Apr 11 2018 /usr/bin/gcc-ranlib-5
lrwxrwxrwx 1 root root 29 Nov 12 2018 /usr/bin/gcc-ranlib-6 -> x86_64-linux-gnu-gcc-ranlib-6
lrwxrwxrwx 1 root root 29 Dec 4 2019 /usr/bin/gcc-ranlib-7 -> x86_64-linux-gnu-gcc-ranlib-7
#gcc原来的指向
# yh @ deepserver3 in ~/.local/bin [1:54:24]
$ which gcc
/usr/bin/gcc
#在加入的路径里添加gcc6的软连接
# yh @ deepserver3 in ~/.local/bin [1:53:48]
$ ln -s /usr/bin/gcc-6 gcc
#退出并保存
# yh @ deepserver3 in ~/.local/bin [1:54:33]
$ exit
(SMAP)
# yh @ deepserver3 in ~/SMAP/extensions [1:54:34]
$ zsh
#可以看到gcc的指向已经变了
# yh @ deepserver3 in ~/SMAP/extensions [1:54:36]
$ which gcc
/home/yh/.local/bin/gcc