使用update-alternatives工具管理C++编译器和Python解释器版本。
安装新版本
C++编译器
以gcc-9
和g++-9
为例:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-9 g++-9
Python解释器
以python3.7
为例:
sudo apt update
sudo apt install python3.7
删除版本列表
C++编译器
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
Python解释器
sudo update-alternatives --remove-all python3
添加版本列表
C++编译器
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 7
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11
Python解释器
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 6
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 7
选择版本
C++编译器
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
Python解释器
sudo update-alternatives --config python3