Ubuntu多版本gcc

无意中看到altenative这个选项,然后就查询了一下.了解了用法.

首先安装多版本的gcc/g++之后,

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50

这里的100,50指的赋给这两个不同版本的gcc的优先级,值越大则优先级越高. 可以在/usr/bin目录下看到多个gcc-<version>,然后就可以使用

sudo update-alternative config gcc

然后就可以看到

(base) ➜  ~ 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-7   100       auto mode
  1            /usr/bin/gcc-7   100       manual mode
  2            /usr/bin/gcc-8   8         manual mode
* 3            /usr/bin/gcc-9   50        manual mode

Press <enter> to keep the current choice[*], or type selection number:

其中gcc-8是系统自带的版本, 另外两个是新安装的. 按照说明选择需要的版本就完成配置了.

(base) ➜  ~ 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-7   100       auto mode
  1            /usr/bin/gcc-7   100       manual mode
  2            /usr/bin/gcc-8   8         manual mode
* 3            /usr/bin/gcc-9   50        manual mode

Press <enter> to keep the current choice[*], or type selection number: 0
update-alternatives: using /usr/bin/gcc-7 to provide /usr/bin/gcc (gcc) in auto mode

现在系统的gcc版本就是gcc-7了

(base) ➜  ~ gcc --version
gcc (Ubuntu 7.5.0-6ubuntu2) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

g++也是同理的操作.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值