环境 ubuntu16.04
1.安装gcc7.3.0 g++7.3.0
sudo ppa-purge ppa:jonathonf/gcc-7.3
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-7
sudo apt-get install g++-7
这里其实有一个问题,我指定的是7.3版本的,安装的却是7.5的,不过问题不大.
2.添加版本及优先级
2.1gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 100
2.2g++
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 100
显示当前的gcc和g++版本
可以看到我已经变成7.5.0版本的了
3.切换不同的gcc和g++版本
3.1gcc
sudo update-alternatives --config gcc
3.2g++
sudo update-alternatives --config g++
参考
https://askubuntu.com/questions/1009433/dependency-issues-while-installing-gcc-7-3-from-jonathon-fs-ppa/1009438?noredirect=1
https://blog.youkuaiyun.com/weixin_35762621/article/details/80336291
https://blog.youkuaiyun.com/xrinosvip/article/details/81177873