在ubuntu系统中,update-alternatives是专门维护系统命令链接符的工具,其可以对某个工具的多个软件版本进行管理,通过它可以很方便的设置系统默认使用哪个命令的哪个软件版本。
当你安装 Linux 时,安装过程有可能同时为你提供多个可用的 Python 版本,因此系统中会存在多个 Python 的可执行二进制文件。
用ls命令来查看系统中都有那些 Python 可用
ls /usr/bin/python*
执行如下命令查看默认的 Python 版本信息
python --version
我们可以使用 update-alternatives 来为整个系统更改 Python 版本。
首先罗列出所有可用的 python 替代版本信息
update-alternatives --list python
将/usr/bin/python2设置的优先级为9
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 9
将/usr/bin/python3设置的优先级为10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
使用下方的命令随时在列出的 Python 替代版本中任意切换成默认python
sudo update-alternatives --config python
一旦我们的系统中不再存在某个 Python 的替代版本时,我们可以将其从 update-alternatives 列表中删除掉。例如,我们可以将列表中的 python2.7 版本移除掉
sudo update-alternatives --remove python /usr/bin/python2
ernatives --remove python /usr/bin/python2
注意:优先级高的默认作为默认版本python



