在 Ubuntu 18.04 中,python3 的默认版本为 3.6
通过Apt安装(使用 deadsnakes PPA 库安装)
- 安装依赖包
$ sudo apt update
$ sudo apt install software-properties-common
- 添加 deadsnakes PPA 源
$ sudo add-apt-repository ppa:deadsnakes/ppa
- 安装 python 3.8
$ sudo apt install python3.8
$ python3.8 -V
Python 3.8.2
配置Python3.8为系统默认Python3
- 将 python 各版本添加到 update-alternatives
$ which python3.8
/usr/bin/python3.8
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
$ which python3.5
/usr/bin/python3.5
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
- 配置 python3 默认指向 python3.8
$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.5 2 auto mode
1 /usr/bin/python3.5 2 manual mode
2 /usr/bin/python3.8 1 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
- 测试 python 版本
$ python3 -V
Python 3.8.2