1. 前言
限于作者能力水平,本文可能存在谬误,因此而给读者带来的损失,作者不做任何承诺。^_^
2. 什么是 update-alternatives?
用于管理系统中功能接近软件的不同版本,使其多版本共存。如Python 2, Python 3.
3. 举例
假设系统中同时安装了Python 2和Python 3,那么系统当前默认使用的Python还是Python 3?我们可以通过update-alternatives工具,来告诉系统,我们默认使用的哪个Python版本。具体操作步骤如下:
3.1 将 Python 2和3纳入到update-alternatives管理
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
可通过如下命令确认上面的操作是否成功:
sudo update-alternatives --list python
该命令会列举已经纳入update-alternatives管理的Python列表。
3.2 配置默认的Python版本
sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3 2 auto mode
1 /usr/bin/python2 1 manual mode
2 /usr/bin/python3 2 manual mode
Press to keep the current choice[*], or type selection number: 1
行首标记了 * 的为当前默认启用的Python版本,可通过输入序号,来改变默认启用的Python版本。
4. 更多关于 update-alternatives 使用方法
man update-alternatives