- 首先可以使用以下命令查看當(dāng)前的python版本:
python3 -V
- 安裝最新版python, 以python 3.8為例:
apt update
apt install python3.8
- 將原版本的python和python3.8添加到
update-alternatives
中:
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
#可以使用 whereis python3 命令在linux中確定python的目錄
#上述命令結(jié)尾的數(shù)字代表優(yōu)先級(jí), 系統(tǒng)跟據(jù)優(yōu)先級(jí)選擇默認(rèn)的python版本
- 可以跟據(jù)需要自由切的
python3
命令的指向:
update-alternatives --config python3
auto mode
是跟據(jù)優(yōu)先級(jí)自動(dòng)選擇.
root@markict:~# update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.8 2 auto mode
1 /usr/bin/python3.6 1 manual mode
2 /usr/bin/python3.8 2 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
- 版本升級(jí)成功:
python3 -V
root@markict:~# python3 -V
Python 3.8.0