| Tested on | Ubuntu 26.04 LTS (host) Ubuntu 24.04 LTS & 22.04 LTS (Docker) |
|---|---|
| Package | python3.12 — 3.12.15-1+resolute1 (26.04 Deadsnakes)3.12.3-1ubuntu0.17 (24.04 archive)3.12.15-1+jammy1 (22.04 Deadsnakes) |
| Lab environment | Host: Resolute Raccoon Containers: public.ecr.aws/ubuntu/ubuntu:24.04 and :22.04 (commands and venv flow verified 2026-10-18) |
| Applies to | Ubuntu 22.04 LTS, 24.04 LTS, and 26.04 LTS |
| Privilege | sudo for apt and PPA; normal user for uv, pyenv, and venv |
| Scope | Install Python 3.12 when a project pins that minor—on 24.04 it is already the distro python3; on 26.04 and 22.04 install 3.12 beside the default. Covers Ubuntu archive, Deadsnakes, uv, and pyenv. For upstream 3.15, use the latest-Python guide in Related guides. |
| Related guides | Install Python 3.11 on Ubuntu Install Python 3.13 on Ubuntu Install Flask on Ubuntu pip command not found |
Install Python 3.12 when an application, wheel, or CI image requires that minor—not because you want the newest upstream CPython.
Python 3.12 lifecycle (October 2026):
- 3.12.15 is the current security release—the series is security-fixes-only
- Upstream security support continues until October 2028
- Prefer a newer supported feature release for new projects unless something pins 3.12
Older tutorials sometimes claim Ubuntu 26.04 needs a source build for Python 3.12 because Deadsnakes did not ship Resolute packages. That is outdated: Deadsnakes now publishes python3.12 (for example 3.12.15-1+resolute1) for resolute—use the PPA, uv, or pyenv instead of compiling unless you have a special build requirement.
Pick an install path:
┌─────────────────────────────────┐
│ Need Python 3.12 on Ubuntu? │
└────────────────┬────────────────┘
│
┌──────────────────┴──────────────────┐
▼ ▼
┌─────────────────────────┐ ┌─────────────────────────────┐
│ Ubuntu 24.04 │ │ Ubuntu 26.04 / 22.04 │
│ python3 is 3.12 │ │ install 3.12 beside default │
│ Ubuntu APT + venv │ │ python3 │
└─────────────────────────┘ └──────────────┬──────────────┘
│
┌────────────────────────────────────┴────────────────────┐
▼ ▼
┌─────────────────────────┐ ┌─────────────────────────────┐
│ Deadsnakes PPA │ │ User-level / many versions │
│ (3.12.x on LTS) │ └──────────────┬──────────────┘
└─────────────────────────┘ ┌────────┴──────────┐
▼ ▼
┌────┐ ┌───────┐
│ uv │ │ pyenv │
└────┘ └───────┘Quick answer: Python 3.12 on Ubuntu by release
| Ubuntu | System python3 |
Python 3.12 source | Recommended path |
|---|---|---|---|
| 26.04 LTS | 3.14 series | Deadsnakes 3.12.15 on resolute | Deadsnakes, uv, or pyenv |
| 24.04 LTS | 3.12 | Official Noble archive | Ubuntu apt |
| 22.04 LTS | 3.10 | Deadsnakes on jammy | Deadsnakes, uv, or pyenv |
Confirm your row with check Ubuntu version before changing repositories.
Python 3.12 availability on Ubuntu 26.04, 24.04, and 22.04
Why the path differs:
- 24.04 — Ubuntu's distro-managed
python3is Python 3.12; use the archive (not a side-by-side “extra” unless you deliberately add Deadsnakes) - 26.04 — default is 3.14; install 3.12 when apps still require that minor
- 22.04 — default is 3.10; install 3.12 alongside 3.10
Install Flask on Ubuntu uses the same .venv pattern on 24.04 with system 3.12.
Python 3.12 lifecycle and Ubuntu package versions
Upstream python.org may show 3.12.15 while python3 --version on 24.04 reports 3.12.3 (or another Noble package revision).
- Ubuntu 24.04 keeps its distro Python on the 3.12.3 package lineage and backports security fixes rather than matching every upstream 3.12.x number
- A lower patch in
aptoutput does not by itself mean your system lacks security fixes—compare Ubuntu security notices and package changelogs when you need certainty - On 26.04 / 22.04, a Deadsnakes or uv build may show a higher 3.12.x patch than Noble's
python3.12package—that is expected when you chose a non-archive interpreter
Before you install: keep Ubuntu's system Python unchanged
python3. Do not remove python3.12, repoint /usr/bin/python3, or “upgrade” system Python with update-alternatives.
Do not:
- Run
sudo update-alternatives --config python3to switch the system default - Replace or symlink over
/usr/bin/python3manually - Purge
python3/python3.12on 24.04 during cleanup
Do instead:
- 24.04 — use distro
python3orpython3.12for the interpreter; put project libraries in a venv - 26.04 / 22.04 — call
python3.12or a venv; leavepython3on the release default
Verify after any install:
readlink -f /usr/bin/python3
python3 --version
python3.12 --version 2>/dev/null || trueExpected series:
- 22.04 —
python3→ 3.10 - 24.04 —
python3→ 3.12 - 26.04 —
python3→ 3.14
Ubuntu 24.04: Use the built-in Python 3.12
Ubuntu 24.04's distro-managed python3 is Python 3.12. You usually do not need Deadsnakes unless you have a rare need for a newer 3.12.x than Noble ships.
Refresh indexes and install versioned packages explicitly:
sudo apt update
sudo apt install python3.12 python3.12-venvpython3 already resolves to 3.12 on a normal desktop install—you can use python3 / python3-venv instead if you prefer metapackages. On a minimal server image, install the python3 metapackage if python3 is not on the system yet (python3.12 alone does not always provide the python3 command).
Verify Python 3.12
Confirm the candidate comes from Ubuntu's noble archive, not a PPA:
apt-cache policy python3.12
python3.12 --version
python3 --versionExample output on 24.04 (package revision may differ after updates):
Python 3.12.3
Python 3.12.3Why Ubuntu may show 3.12.3 while python.org lists 3.12.15
See Python 3.12 lifecycle and Ubuntu package versions above—Noble backports fixes without always bumping the upstream patch number you see on python.org.
Ubuntu 26.04 and 22.04: Install Python 3.12 with Deadsnakes
Deadsnakes notes:
- Community-maintained third-party PPA—not Canonical's default archive
- Convenient for python3.12 beside system
python3on resolute and jammy - Maintainers do not guarantee the same security-update cadence as Ubuntu's official packages—weigh that for production workloads
- On 24.04, stay on Ubuntu's python3.12 unless you have a specific reason to add the PPA
Add the Deadsnakes PPA for Python 3.12 on Ubuntu
Enable the PPA with add-apt-repository when needed:
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt updateVerify the Python 3.12 package source on Ubuntu
Run apt-cache policy before you install so you know which suite and PPA will satisfy python3.12:
apt-cache policy python3.12Confirm:
- Candidate is from
ppa.launchpadcontent.net/deadsnakes/ppa - Suite is resolute on 26.04 or jammy on 22.04
Example on Ubuntu 26.04:
python3.12:
Candidate: 3.12.15-1+resolute1
Version table:
3.12.15-1+resolute1 500
500 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu resolute/main amd64 PackagesPatch numbers change when the PPA publishes new builds.
Install Python 3.12 and venv
Install the interpreter and venv module, then compare python3.12 to system python3:
sudo apt install python3.12 python3.12-venv
python3.12 --version
python3 --versionExample on 26.04 after install:
Python 3.12.15
Python 3.14.4python3 stays on the 3.14 series; only python3.12 reports 3.12.15.
Optional development headers
Install python3.12-dev only when compiling C extensions or building against Python headers:
sudo apt install python3.12-devCreate a Python 3.12 virtual environment
A venv does not install Python 3.12—it isolates packages around an interpreter that already exists.
On 24.04, either python3.12 or python3 is fine when it reports 3.12. On 26.04 / 22.04, use python3.12:
python3.12 -m venv ~/venvs/py312
source ~/venvs/py312/bin/activateVerify Python and pip inside the venv
With the venv active, confirm both the interpreter and pip point into the venv:
python --version
python -m pip --versionExpected shape:
Python 3.12.15
pip ... from .../venvs/py312/lib/python3.12/site-packages/pip (python 3.12)Upgrade pip inside the venv:
python -m pip install --upgrade pipOn 24.04 (and other current releases), do not install application dependencies globally with sudo pip or pip install --break-system-packages on system python3—PEP 668 marks the distro interpreter as externally managed. Use the venv. If pip itself is missing, see pip command not found.
Sanity-check common modules:
python -c "import ssl, sqlite3, bz2, lzma; print('Python 3.12 OK')"Deactivate with deactivate.
Alternative: Install Python 3.12 with uv
uv fits user-level Python without a PPA:
- Managed installs under your account—not
/usr/bin/python3 uv python install 3.12tracks the latest 3.12 patch uv publishes- A developer-managed Python installation—not an Ubuntu
python3package
| Method | Best for |
|---|---|
| Ubuntu 24.04 apt | Distro-owned 3.12 as system python3 |
| Deadsnakes | APT-managed python3.12 beside the default on 26.04 / 22.04 |
| uv | Fast user-level Python and venvs |
| pyenv | Many interpreter versions per project |
Install uv and create a 3.12 venv:
curl -LsSf https://astral.sh/uv/install.sh | sh
uv python install 3.12
uv venv --python 3.12 .venv
source .venv/bin/activate
python --versionAlternative: Use pyenv for multiple Python versions
pyenv compiles CPython under ~/.pyenv/versions/ (build dependencies required). Full setup: install latest Python on Ubuntu.
After pyenv is installed:
pyenv install 3.12
pyenv local 3.12
python --versionCustom tarball builds stay on the latest-Python page—this article focuses on apt, Deadsnakes, uv, and pyenv.
Update Python 3.12
Ubuntu 24.04 — normal archive updates:
sudo apt update
sudo apt install python3.12 python3.12-venvDeadsnakes on 26.04 / 22.04 — same pattern after apt update:
sudo apt update
sudo apt install python3.12 python3.12-venvuv:
uv python upgrade 3.12pyenv — install a newer 3.12.x patch and update .python-version or pyenv local.
Uninstall Python 3.12
Ubuntu 24.04
Delete project venvs only—do not apt remove python3.12.
Ubuntu 26.04 and 22.04
Inspect what you installed:
apt-cache policy python3.12
dpkg -l | grep '^ii python3.12'Remove only packages you added (omit python3.12-dev if you never installed it):
sudo apt remove python3.12 python3.12-venv- venv directories are not removed by
apt remove—delete~/venvs/or./.venvyourself - Drop the Deadsnakes PPA only when no other Deadsnakes Python packages still need it
Broader cleanup: Uninstall Python on Ubuntu.
Troubleshooting Python 3.12 on Ubuntu
| Symptom | Likely cause | Fix |
|---|---|---|
Unable to locate package python3.12 on 26.04 / 22.04 |
PPA missing or stale indexes | Add Deadsnakes, sudo apt update, apt-cache policy python3.12 |
python3 shows 3.14 on 26.04 |
Expected | Use python3.12 or a venv |
python3 shows 3.10 on 22.04 |
Expected | Use python3.12 or a venv |
python3.12 -m venv fails |
python3.12-venv missing |
sudo apt install python3.12-venv |
externally-managed-environment on 24.04 |
pip against system python3 |
Create a venv; use python -m pip inside it |
pip targets wrong Python |
venv not active or PATH issue | Activate venv; use python -m pip |
apt breaks after changing python3 |
System interpreter retargeted | Restore Ubuntu python3 packages; avoid update-alternatives on python3 |
pyenv build missing _ssl / sqlite3 |
Build deps missing | Install pyenv build deps from latest-Python guide, or use apt/Deadsnakes/uv |
Summary: install Python 3.12 on Ubuntu
Install Python 3.12 when compatibility requires that minor.
- Lifecycle — security-fixes-only through October 2028
- 24.04 — distro
python3is 3.12; use Ubuntu apt + venvs; do not uninstall 3.12 - 26.04 — Deadsnakes 3.12.15 on resolute (no source compile required for most users)
- 22.04 — install 3.12 alongside 3.10 with Deadsnakes, uv, or pyenv
- Safety — never repoint
/usr/bin/python3; use venvs andpython -m pip
If you need the newest supported Python rather than specifically 3.12, use install latest Python on Ubuntu from Related guides.
References
- Deadsnakes PPA
- Python 3.12.15 release notes
- Python 3.12 documentation
- Ubuntu Noble
python3.12package - PEP 668 — externally managed environments
- uv — Python versions
Frequently Asked Questions
Is Python 3.12 the Ubuntu 24.04 default?
Yes—Ubuntu 24.04's distro-managed python3 is Python 3.12 (package revisions update with security fixes).
Why install python3.12 on Ubuntu 26.04?
When an application or CI image pins 3.12 while the system default is 3.14. Deadsnakes ships python3.12 for resolute—you do not need to compile from source for a typical side-by-side install.
Should I replace Ubuntu's python3 with Python 3.12?
- 24.04 —
python3already is 3.12; do not repoint or remove it - 22.04 / 26.04 — no; use
python3.12or a virtual environment and leave systempython3alone
Why does Ubuntu 24.04 show Python 3.12.3 when python.org has 3.12.15?
Noble keeps the 3.12.3 package lineage and backports security fixes. The number in python3 --version is not the same as the latest upstream patch on python.org.
Should I use Deadsnakes on Ubuntu 24.04?
Usually no—use Ubuntu's archive python3.12. Add Deadsnakes only when you have a specific need that Noble's package does not meet.

