ubuntu安装不同版本的gcc/g++

安装其他二进制版本的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
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值