安装其他二进制版本的gcc/g++
以下以gcc为例,g++命令相同
- 查看目前的gcc版本
gcc --version
gcc --version
- 查看可以安装的gcc版本
apt list gcc-*
apt list g++-*
- 安装不同版本的gcc(以gcc-9)为例
apt install gcc-9
apt install g++-9
配置安装的版本
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 50
其中的50表示版本的权重,当配置多个版本的gcc时,系统会选择权重最高版本作为默认版本
除了配置更高的权重,还可以手动配置
sudo update-alternatives --config gcc
There are 3 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-9 50 auto mode
1 /usr/bin/g++-9 50 manual mode
2 /usr/bin/gcc-7 10 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
sudo update-alternatives --config g++
There are 2 choices for the alternative g++ (providing /usr/bin/g++).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/g++-9 50 auto mode
1 /usr/bin/g++-7 10 manual mode
2 /usr/bin/g++-9 50 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2