ubuntu 20.04如何切换gcc/g++/python的版本

当系统同时存在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 update

sudo apt install gcc-9
sudo apt install g++-9

sudo apt install gcc-10
sudo apt install g++-10

sudo 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 10

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10

sudo 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 gcc

sudo 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 mode
  2            /usr/bin/gcc-9    9         manual mode

Press <enter> to keep the current choice[*], or type selection number: 0
$
  • 19
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 30
    评论
评论 30
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值