使用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 <目錄>