ubuntu 20.04如何切換gcc/g++/python的版本
- 1 安裝gcc/g++/python
- 2 設置gcc/g++/python的備選項
- 3 選擇當前系統要使用的gcc/g++/python版本
- 3.1 切換gcc/g++/python版本
- 3.2 切換示例
當系統同時存在gcc-9以及gcc-10時該如何切換讓當前的系統gcc版本指向gcc-9或是gcc-10呢?g++也同樣如此。
面臨更嚴重問題的python更是如此,ubuntu 目前默認安裝的python版本是2.7,而我們經常使用的版本為3.xx。
1 安裝gcc/g++/python
同時安裝gcc/g+±9,gcc/g+±10,python2/3
sudo apt-get install updatesudo apt install gcc-9
sudo apt install g++-9sudo apt install gcc-10
sudo apt install g++-10sudo apt install python
sudo apt install python3
2 設置gcc/g++/python的備選項
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 10sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 2
3 選擇當前系統要使用的gcc/g++/python版本
3.1 切換gcc/g++/python版本
sudo update-alternatives --config gccsudo update-alternatives --config g++sudo update-alternatives --config python
3.2 切換示例
以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 mode2 /usr/bin/gcc-9 9 manual modePress <enter> to keep the current choice[*], or type selection number: 0
$