How to Install Python 3.12 on Ubuntu

Deepak Prasad
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
Short on time?Beta Get the gist of this 9-minute read in seconds, then ask follow-up questions

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 python3 is 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 apt output 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.12 package—that is expected when you chose a non-archive interpreter

Before you install: keep Ubuntu's system Python unchanged

IMPORTANT
On Ubuntu 24.04, Python 3.12 is the operating system's python3. Do not remove python3.12, repoint /usr/bin/python3, or “upgrade” system Python with update-alternatives.

Do not:

  • Run sudo update-alternatives --config python3 to switch the system default
  • Replace or symlink over /usr/bin/python3 manually
  • Purge python3 / python3.12 on 24.04 during cleanup

Do instead:

  • 24.04 — use distro python3 or python3.12 for the interpreter; put project libraries in a venv
  • 26.04 / 22.04 — call python3.12 or a venv; leave python3 on the release default

Verify after any install:

bash
readlink -f /usr/bin/python3
python3 --version
python3.12 --version 2>/dev/null || true

Expected 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:

bash
sudo apt update
sudo apt install python3.12 python3.12-venv

python3 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:

bash
apt-cache policy python3.12
python3.12 --version
python3 --version

Example output on 24.04 (package revision may differ after updates):

output
Python 3.12.3
Python 3.12.3

Why 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 python3 on 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:

bash
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

Verify 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:

bash
apt-cache policy python3.12

Confirm:

  • Candidate is from ppa.launchpadcontent.net/deadsnakes/ppa
  • Suite is resolute on 26.04 or jammy on 22.04

Example on Ubuntu 26.04:

output
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 Packages

Patch 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:

bash
sudo apt install python3.12 python3.12-venv
python3.12 --version
python3 --version

Example on 26.04 after install:

output
Python 3.12.15
Python 3.14.4

python3 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:

bash
sudo apt install python3.12-dev

Create 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:

bash
python3.12 -m venv ~/venvs/py312
source ~/venvs/py312/bin/activate

Verify Python and pip inside the venv

With the venv active, confirm both the interpreter and pip point into the venv:

bash
python --version
python -m pip --version

Expected shape:

output
Python 3.12.15
pip ... from .../venvs/py312/lib/python3.12/site-packages/pip (python 3.12)

Upgrade pip inside the venv:

bash
python -m pip install --upgrade pip

On 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:

bash
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.12 tracks the latest 3.12 patch uv publishes
  • A developer-managed Python installation—not an Ubuntu python3 package
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:

bash
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 --version

Alternative: 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:

bash
pyenv install 3.12
pyenv local 3.12
python --version

Custom 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:

bash
sudo apt update
sudo apt install python3.12 python3.12-venv

Deadsnakes on 26.04 / 22.04 — same pattern after apt update:

bash
sudo apt update
sudo apt install python3.12 python3.12-venv

uv:

bash
uv python upgrade 3.12

pyenv — install a newer 3.12.x patch and update .python-version or pyenv local.


Uninstall Python 3.12

Ubuntu 24.04

IMPORTANT
Do not remove Python 3.12 from Ubuntu 24.04. The operating system and APT-managed tools depend on it.

Delete project venvs only—do not apt remove python3.12.

Ubuntu 26.04 and 22.04

Inspect what you installed:

bash
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):

bash
sudo apt remove python3.12 python3.12-venv
  • venv directories are not removed by apt remove—delete ~/venvs/ or ./.venv yourself
  • 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 python3 is 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 and python -m pip

If you need the newest supported Python rather than specifically 3.12, use install latest Python on Ubuntu from Related guides.


References


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 — python3 already is 3.12; do not repoint or remove it
  • 22.04 / 26.04 — no; use python3.12 or a virtual environment and leave system python3 alone

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.

Finished reading?Beta Get the key takeaways in seconds, then ask follow-up questions
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware.

  • Debian
  • Ubuntu
  • Linux
  • Red Hat Enterprise Linux
  • Shell Script
  • System Administration