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

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

  • 1 安装gcc/g++/python
  • 2 设置gcc/g++/python的备选项
  • 3 选择当前系统要使用的gcc/g++/python版本
    • 3.1 切换gcc/g++/python版本
    • 3.2 切换示例

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

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2023年11月27日
下一篇 2023年11月27日

相关推荐