[Linux] 更改 Python 版本
- 2022.11.23
- Linux Python Ubuntu 22.04
- Ubuntu_22_04
確認命令來源1type command in Linux with Examples
type pythonX
type -a pythonX
(查 alias(別名))
用 update-alternatives 切換
安裝自定選項
sudo update-alternatives --install /usr/bin/pythonX pythonX /usr/bin/pythonX.Y 300
※ 300為優先度,數值越高優先度越高
查看
update-alternatives --display pythonX
指定預設選項
sudo update-alternatives --config pythonX
編輯 alias
編輯 ~/.bashrc
更改 Symbolic Link
- 確認 pythonX 的 symbolic link
ls -l /usr/bin | grep pythonX
→lrwxrwxrwx 1 root root 25 Oct 23 05:43 pythonX -> /etc/alternatives/pythonX
ls -l /etc/alternatives | grep pythonX
→lrwxrwxrwx 1 root root 19 Oct 23 05:43 pythonX -> /usr/bin/pythonX.Y
- 得知
/usr/bin/pythonX -> /etc/alternatives/pythonX -> /usr/bin/pythonX.Y
/usr/bin/pythonX
並非實體檔案,故接續下一步
- 刪除原本的 pythonX:
sudo rm /usr/bin/pythonX
- 創建新的 symbolic:
sudo ln -s /usr/bin/pythonX.X /usr/bin/pythonX
Last Updated on 2023/10/23 by A1go