当系统同时存在gcc-9以及gcc-10时该如何切换让当前的系统gcc版本指向gcc-9或是gcc-10呢?g++也同样如此。
面临更严重问题的python更是如此,ubuntu 目前默认安装的python版本是2.7,而我们经常使用的版本为3.xx。
同时安装gcc/g+±9,gcc/g+±10,python2/3
sudo apt-get install update
sudo apt install gcc-9
sudo apt install g++-9
sudo apt install gcc-10
sudo apt install g++-10
sudo apt install python
sudo apt install python3
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 2
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
sudo update-alternatives --config python
以gcc为例
$ sudo update-alternatives --config gcc
[sudo] password for test:
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/gcc-10 10 auto mode
* 1 /usr/bin/gcc-10 10 manual mode
2 /usr/bin/gcc-9 9 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
$