Linux下使用update-alternatives切换python版本

使用update-alternatives进行 python版本管理。

linu系统默认安装的python版本比较低,新安装python之后要做很多软链接或者环境变量的配置。update-alternatives 命令用于处理linux系统中软件版本的切换,使用update-alternatives可以很方便的进行python版本管理

查看可配置python版本

[lighthouse@VM-20-7-centos ~]$ update-alternatives --display python
python - 状态为手工。
 链接当前指向 /usr/bin/python3.9
/usr/libexec/no-python - 优先度 404
 从属 unversioned-python:(null)
 从属 unversioned-python-man:/usr/share/man/man1/unversioned-python.1.gz
/usr/bin/python3 - 优先度 300
 从属 unversioned-python:/usr/bin/python3
 从属 unversioned-python-man:/usr/share/man/man1/python3.1.gz
/usr/bin/python3.9 - 优先度 209
 从属 unversioned-python:/usr/bin/python3.9
 从属 unversioned-python-man:/usr/share/man/man1/python3.9.1.gz
当前“最佳”版本是 /usr/libexec/no-python。
[lighthouse@VM-20-7-centos ~]$ update-alternatives --config python

配置python版本

[lighthouse@VM-20-7-centos ~]$ update-alternatives --config python

共有 3 个提供“python”的程序。

  选项    命令
-----------------------------------------------
*  1           /usr/libexec/no-python
   2           /usr/bin/python3
 + 3           /usr/bin/python3.9

按 Enter 保留当前选项[+],或者键入选项编号:
#输入相应的编号进行版本切换

切换后版本如下:

[lighthouse@VM-20-7-centos ~]$ python -V
Python 3.9.6
[lighthouse@VM-20-7-centos ~]$

详细使用方式

[lighthouse@VM-20-7-centos ~]$ update-alternatives
alternatives(备用)版本 1.19.1 - 版权 (C) 2001 红帽公司
在 GNU 公共许可条款下,本软件可被自由地重发行。

用法:alternatives --install <链接> <名称> <路径> <优先度>
                    [--initscript <服务>]
                    [--family <家族>]
                    [--slave <从属链接> <从属名称> <从属路径>]*
       alternatives --remove <名称> <路径>
       alternatives --auto <名称>
       alternatives --config <名称>
       alternatives --display <名称>
       alternatives --set <名称> <路径>
       alternatives --list
       alternatives --remove-all <名称>
       alternatives --add-slave <名称> <路径> <从属链接> <从属名称> <从属路径>
       alternatives --remove-slave <名称> <路径> <从属名称>

common options: --verbose --test --help --usage --version --keep-missing --keep-foreign
                --altdir <目录> --admindir <目录>
posted @ 2022-03-28 17:05  bye0ond  阅读(731)  评论(0编辑  收藏  举报