安装gcc9
sudo apt install gcc-9 g++-9
查看已安装的gcc版本
dpkg -l | grep gcc
切换gcc版本
sudo update-alternatives --config gcc
遇到报错
There is only one alternative in link group gcc (providing /usr/bin/gcc): /usr/bin/gcc-4.7
Nothing to configure.
可能原因 gcc9未添加软链接
解决方法
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50 --slave /usr/bin/g++ g++ /usr/bin/g++-9
执行该命令后再执行切换版本命令
~$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-7 100 auto mode
1 /usr/bin/gcc-7 100 manual mode
2 /usr/bin/gcc-9 50 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
若输入2,则切换到gcc版本9
查看gcc版本
gcc -v
|