在 Ubuntu 上能安装的 Python 版本,主要取决于 Ubuntu 版本本身 以及你 是否使用官方源 / PPA / 编译安装。下面分情况说明:
注:Ubuntu 20.04 及以后,系统默认 Python 是 Python 3
| Ubuntu 版本 | 默认 Python 3 版本 |
|---|---|
| Ubuntu 18.04 | Python 3.6 |
| Ubuntu 20.04 | Python 3.8 |
| Ubuntu 22.04 | Python 3.10 |
| Ubuntu 24.04 | Python 3.12 |
⚠️ 不要卸载系统 Python,否则可能导致系统命令(如 apt)失效。
不同 Ubuntu 版本官方源里能装的 Python:
安装示例:
sudo apt update
sudo apt install python3.11
可以安装 几乎全部 Python 版本(3.7 ~ 3.13)
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12
支持版本示例:
适合开发,不影响系统 Python:
sudo apt install build-essential libssl-dev zlib1g-dev
curl https://pyenv.run | bash
然后可以安装任意版本:
pyenv install 3.13.0
pyenv install 3.7.17
✅ 适合:
如果你告诉我:
我可以给你 最合适的安装方案。