Install or Upgrade Python on Ubuntu 24.04 and 22.04 Safely

Tech reviewed: Deepak Prasad
Install or Upgrade Python on Ubuntu 24.04 and 22.04 Safely

If sudo apt install python3 reports that Python is already the newest package, but python3 --version still shows 3.10 on Ubuntu 22.04 or 3.12 on Ubuntu 24.04, you are seeing normal Ubuntu behavior—not a failed install. Ubuntu pins a default python3 for each release so system tools stay stable. This guide shows how to install the latest upstream Python or upgrade your own projects to a newer line side-by-side with that default, create a working virtual environment, and avoid replacing /usr/bin/python3.

Tested on: Python 3.14.6; system python3 3.13.3; kernel 6.14.0-37-generic; Ubuntu 25.04.

The source-build (make altinstall) and virtual-environment steps were run on this host. Deadsnakes PPA commands and package names match the packages published for Ubuntu 22.04 (jammy) and 24.04 (noble) on the Deadsnakes PPA. On an LTS machine, run the PPA block there; expect python3.14 --version to report the PPA patch level (for example 3.14.6) while python3 --version stays on the release default.


Why Ubuntu does not always provide the latest Python

Ubuntu chooses one primary python3 per release and updates it on a stability schedule. That version powers apt hooks, system scripts, and many .deb packages. Upstream Python on python.org moves faster—Python 3.14.6 is the current stable download at the time of writing—so the default python3 on an LTS system is often several minor releases behind.

Ubuntu version Default python3 (typical) Notes
Ubuntu 22.04 LTS (jammy) Python 3.10 Deadsnakes ships newer versions such as 3.13 and 3.14; it does not repackage 3.10 because Ubuntu already provides it.
Ubuntu 24.04 LTS (noble) Python 3.12 Deadsnakes ships 3.13, 3.14, and others; it does not repackage 3.12 because Ubuntu already provides it.
Ubuntu 26.04 (resolute) Python 3.14 Check python3 --version for the exact patch level; Deadsnakes generally does not repackage the same version Ubuntu ships.

The safe rule for this article: install the latest Python next to the system Python. Do not remove python3, do not overwrite /usr/bin/python3, and do not point pip at the system interpreter with sudo.


Check your current Python version

Run these checks before you install anything. They explain the “already newest” message and show whether a versioned binary is already present.

Check your Ubuntu release:

bash
lsb_release -ds

Example on Ubuntu 24.04:

text
Ubuntu 24.04.2 LTS

Check the default interpreter Ubuntu wired to python3:

bash
python3 --version
which python3

Example on Ubuntu 24.04 before adding a newer Python:

text
Python 3.12.3
/usr/bin/python3

See whether a newer versioned binary is already installed (adjust the minor version if you target 3.13 instead of 3.14):

bash
python3.14 --version
command -v python3.14

If the command is missing, the shell reports command not found—that is expected until you install from Deadsnakes or build from source.

See what apt considers the newest default Python package:

bash
apt-cache policy python3
apt-cache policy python3.14

On Ubuntu 24.04, python3 may show a candidate with no python3.14 package until you add the Deadsnakes PPA:

text
python3:
  Installed: 3.12.3-0ubuntu2
  Candidate: 3.12.3-0ubuntu2
python3.14:
  Installed: (none)
  Candidate: (none)

After enabling Deadsnakes on jammy or noble, apt-cache policy python3.14 should list a candidate such as 3.14.6-1+noble1.


Two Python versions on one system is normal

A clean Ubuntu LTS install usually has one system Python: python3 points at the release default (3.10 or 3.12). After you follow this guide, having two interpreters is expected—not a misconfiguration:

Command Typical role
python3 Ubuntu system default; leave it for apt and OS tools
python3.14 (or python3.15) Newer interpreter you installed for your projects

List versioned binaries Ubuntu and Deadsnakes provide:

bash
ls /usr/bin/python3* 2>/dev/null
command -v python3.14 python3.15 2>/dev/null

Use the versioned binary (python3.14, python3.15) or a virtual environment for application work. Do not symlink or update-alternatives over /usr/bin/python3 unless you accept breaking system packages.


Choose the right installation method

Pick one primary path. You can keep a source-built python3.14 under /usr/local/bin while the system python3 stays under /usr/bin—they coexist by design.

Method Best for Notes
Ubuntu apt repo Default supported Python for your release Safest for system tools; may not match the latest python.org release.
Deadsnakes PPA Stable 3.14 or pre-release 3.15 on Ubuntu LTS Convenient on 22.04/24.04; third-party PPA—review trust and update policy for production servers.
Source build with make altinstall Exact upstream tarball from python.org You manage rebuilds; altinstall avoids clobbering python3. See source install below.
pyenv Many versions per user or project Use when you switch often between three or more lines; see the short note near the end.

Deadsnakes describes itself as providing “new and old Python versions for Ubuntu.” pyenv focuses on installing and switching multiple interpreters per user or directory—useful when you juggle more than one newer version, not only when you need a single latest build.


Install latest Python from source

Use this when you want the exact tarball from python.org or when no Deadsnakes package exists for your Ubuntu series.

Run make altinstall, not make install. A normal install can create or overwrite /usr/local/bin/python3 and confuse tools that expect Ubuntu’s pinned interpreter. altinstall installs only versioned binaries such as python3.14 or python3.15 under /usr/local and leaves system python3 alone.

Install build dependencies once (shared by both versions below):

bash
sudo apt update
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev \
  libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev

Pick one subsection—3.14 stable or 3.15 pre-release. Each block is a full source install for that version.

Python 3.14 (stable) from source

Download and extract the current stable release (adjust the patch version if a newer one is on python.org):

bash
cd /tmp
curl -fsSLO https://www.python.org/ftp/python/3.14.6/Python-3.14.6.tgz
tar -xf Python-3.14.6.tgz
cd Python-3.14.6

Configure and build. A plain ./configure is enough; add --enable-optimizations only if you accept a much longer PGO build:

bash
./configure
make -j"$(nproc)"
sudo make altinstall

Verify:

bash
python3.14 --version
which python3.14
python3 --version

Example from a successful altinstall test:

text
$ python3.14 --version
Python 3.14.6
$ which python3.14
/usr/local/bin/python3.14
$ python3 --version
Python 3.13.3

System python3 stays on the Ubuntu package; python3.14 lives under /usr/local/bin. To upgrade later, download a newer 3.14 tarball, rebuild, and run sudo make altinstall again.

Python 3.15 (pre-release) from source

Python 3.15 is still in beta at the time of writing—use it for testing, not production servers. Download the current pre-release from the Python 3.15.0 release folder (adjust the beta tag if a newer one is published):

bash
cd /tmp
curl -fsSLO https://www.python.org/ftp/python/3.15.0/Python-3.15.0b2.tgz
tar -xf Python-3.15.0b2.tgz
cd Python-3.15.0b2

Configure, build, and install:

bash
./configure
make -j"$(nproc)"
sudo make altinstall
python3.15 --version
which python3.15

Expected output shape:

text
Python 3.15.0b2
/usr/local/bin/python3.15

When 3.15 reaches a final stable release, rebuild from the stable tarball the same way.


Install latest Python using the Deadsnakes PPA

This is the main practical path on Ubuntu 22.04 and 24.04 when you want a packaged interpreter without compiling. The Deadsnakes PPA publishes versioned packages for jammy and noble.

Add the PPA once before either version subsection below:

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

Pick one subsection—3.14 stable or 3.15 pre-release. Third-party .deb Python modules from Ubuntu’s main archive target the default python3, not Deadsnakes builds—use pip inside a virtual environment for project packages.

Python 3.14 (stable) from Deadsnakes

Install the stable interpreter and packages for venvs and C extensions:

bash
sudo apt install -y python3.14 python3.14-venv python3.14-dev

Verify with the versioned command—not python3:

bash
python3.14 --version
which python3.14
python3 --version

Expected shape on noble or jammy:

text
Python 3.14.6
/usr/bin/python3.14

On Ubuntu 24.04, python3 --version should still show 3.12.x; on 22.04, 3.10.x. Do not repoint /usr/bin/python3 to 3.14.

Optional companion packages:

  • python3.14-distutils — only on older lines where distutils is split out

Python 3.15 (pre-release) from Deadsnakes

Python 3.15 is still in beta—for experiments, not production. If you skipped the PPA steps above, run them first, then install:

bash
sudo apt install -y python3.15 python3.15-venv python3.15-dev
python3.15 --version
which python3.15
python3 --version

Expected output shape:

text
Python 3.15.0b2
/usr/bin/python3.15

System python3 must remain unchanged. Refresh the package when Deadsnakes publishes a newer beta or the final 3.15 release.


Create a virtual environment after installing a new Python

Installing python3.14 or python3.15 gives you a new interpreter binary—it does not automatically isolate project packages (requests, django, and so on). A virtual environment (venv) is a small directory that:

  • pins one Python version for a project or experiment
  • keeps pip installs out of the system interpreter and away from PEP 668 restrictions on /usr/bin/python3
  • lets you delete the project environment later without touching Ubuntu’s python3

Run these steps after you install a versioned Python from Deadsnakes or source. Replace 3.14 with 3.15 (or another line) everywhere in the commands if that is what you installed.

Step 1: Install the matching venv package (Deadsnakes only)

If you used the Deadsnakes PPA, install the -venv package for your version (often bundled with the main package, but install it explicitly if venv fails):

bash
sudo apt install -y python3.14-venv
# pre-release example:
# sudo apt install -y python3.15-venv

Source installs from make altinstall usually include ensurepip; you can skip this apt step unless python3.14 -m venv errors.

Step 2: Create and activate the venv

Use the same versioned binary you installed—not bare python3:

bash
python3.14 -m venv ~/venvs/myproject
source ~/venvs/myproject/bin/activate
python --version
python -m pip install --upgrade pip

Pre-release example:

bash
python3.15 -m venv ~/venvs/py315-beta
source ~/venvs/py315-beta/bin/activate
python --version

After source .../activate, the shell command python points at the venv’s interpreter (3.14 or 3.15), not system python3.

Step 3: Install packages inside the venv

bash
python -m pip install requests

Example after activating a 3.14 venv:

text
$ python --version
Python 3.14.6
$ python -m pip --version
pip 26.1.2 from /home/you/venvs/myproject/lib/python3.14/site-packages/pip (python 3.14)

Leave the venv with deactivate. Prefer python -m pip over bare pip whenever multiple Python versions exist on the host.

If global python3 -m pip install fails on the system interpreter, that is expected on Ubuntu 23.04+:

text
error: externally-managed-environment

Create a venv with your new versioned Python instead—do not use sudo pip on /usr/bin/python3.

For packaging workflows after your venv is ready, see create a Python package and pip requirements.txt.


How to install or upgrade Python on Ubuntu safely

On Ubuntu, “upgrade Python” almost never means “replace the system python3 package in place.” It means add a newer interpreter beside the system default, then move your project to it. The install steps above (3.14 stable or 3.15 pre-release) are the upgrade path for your code—you do not uninstall the old system python3.

Follow this pattern:

  1. Install the newer version (python3.14, python3.15, or a source altinstall) without removing the default python3.
  2. Do not delete /usr/bin/python3 or repoint it with alternatives for system-wide use.
  3. Create a new virtual environment with the newer interpreter.
  4. Reinstall dependencies (python -m pip install -r requirements.txt or your lockfile workflow). For Git-based deps, see install a Python package from GitHub.
  5. Update project-specific paths only: shebangs (#!/usr/bin/env python3.14 or venv python), systemd ExecStart=, cron entries, CI images, and your IDE interpreter setting.
  6. Run your test suite before decommissioning the old venv.

Upgrading Ubuntu itself (for example 22.04 → 24.04) may bump the default python3 as part of the release. That is separate from installing python.org’s latest minor release on a single LTS install.


Troubleshooting

python3 still shows the old version after installing a new Python

Expected. Installing python3.14 does not change python3. Use python3.14 explicitly or activate a venv created with that interpreter.

python3.14 or python3.15: command not found

The versioned package is not installed, or /usr/local/bin is not on your PATH for source builds. Install from Deadsnakes or finish make altinstall, then run command -v python3.14 or command -v python3.15.

Unable to locate package python3.14 or python3.15

Common causes:

  • Deadsnakes PPA not added, or sudo apt update not run afterward.
  • Wrong Ubuntu series—the PPA publishes builds for jammy, noble, and resolute; very old or non-LTS versions may lack packages.
  • Typo in the package name (use python3.14 or python3.15, not python3.14.6).

ensurepip is disabled / python3.14 -m venv or python3.15 -m venv fails

Install the matching venv package:

bash
sudo apt install -y python3.14-venv
# or for pre-release:
sudo apt install -y python3.15-venv

For source installs, ensurepip runs during altinstall; if venv still fails, confirm the build finished without import errors (python3.14 -m venv /tmp/testvenv).

externally-managed-environment

You tried to pip install into the OS-managed python3. Create a venv with your target interpreter instead:

bash
python3.14 -m venv ~/venvs/myproject
source ~/venvs/myproject/bin/activate
python -m pip install <package>

pip installs into the wrong Python version

Always use python -m pip from the interpreter you intend—especially inside a venv after source .../bin/activate. Avoid bare pip or pip3 when multiple Python versions coexist; they may map to the system default.

sudo apt install python3 says python3 is already the newest

That refers only to the default Ubuntu package. Install python3.14 or python3.15 from Deadsnakes, or build from source, for a newer line.


When to use pyenv instead

Use pyenv when you routinely switch between three or more versions (3.10 for legacy, 3.12 for one service, 3.14 for another) on the same user account. pyenv installs interpreters under ~/.pyenv and can set a per-directory version with .python-version.

For installing or upgrading to one newer Python on Ubuntu 22.04 or 24.04, Deadsnakes or a single source altinstall is usually simpler than pyenv.


Summary

Ubuntu pins python3 per release for stability, so apt install python3 can be “newest” while still older than python.org. On 22.04 and 24.04, add the Deadsnakes PPA and install stable python3.14 with matching -venv and -dev packages, or optional pre-release python3.15 for testing—or build from the official tarball with make altinstall. Never use make install and never replace /usr/bin/python3. Having python3 and python3.14 side-by-side is normal. Create a virtual environment, use python -m pip inside it, and point your project at the venv or versioned binary when you upgrade application code. Use pyenv only when you juggle many versions on one workstation.


References

Frequently Asked Questions

1. Why does python3 --version still show an old version after I install Python 3.14?

Ubuntu keeps python3 as the release default for apt and system tools. A newer interpreter is installed as python3.14 (or similar) and does not replace /usr/bin/python3 unless you deliberately change alternatives or symlinks—which you should avoid.

2. Is it safe to replace /usr/bin/python3 with the latest Python on Ubuntu?

No. Replacing the system python3 can break apt, cloud-init, and other packages that depend on the Ubuntu-pinned version. Install the latest Python side-by-side and use python3.14 or a project virtual environment instead.

3. What is the easiest way to install the latest Python on Ubuntu 22.04 or 24.04?

For most LTS users, add the Deadsnakes PPA, install python3.14 with matching python3.14-venv and python3.14-dev packages, then create a venv with python3.14 -m venv. Use source build with make altinstall when you need the exact upstream tarball from python.org.

4. Why does apt say python3 is already the newest version but I still need a newer Python?

apt only tracks the Python version Ubuntu ships for your release. That version is pinned for stability and may lag python.org. Installing python3.14 from Deadsnakes or building from source adds a separate interpreter without upgrading the default python3 package.

5. How do I upgrade Python on Ubuntu for my project without breaking the system?

Install the newer Python beside the old one, create a fresh virtual environment with the new interpreter, reinstall dependencies with python -m pip, and update project paths (shebangs, systemd units, cron, IDE interpreter) to point at the venv or versioned binary—not at /usr/bin/python3.

6. Is it normal to have multiple Python versions on Ubuntu after I install a newer one?

Yes. Ubuntu keeps python3 for system tools and adds a separate versioned binary such as python3.14. That side-by-side layout is expected—use the versioned command or a venv, and do not replace /usr/bin/python3.

7. How do I install Python 3.15 pre-release on Ubuntu 22.04 or 24.04?

After adding the Deadsnakes PPA, install python3.15 with python3.15-venv and python3.15-dev, or build a pre-release tarball from python.org with make altinstall. Treat 3.15 as beta software—not for production servers until it reaches a stable release.

8. When should I use pyenv instead of the Deadsnakes PPA?

Use pyenv when you need several Python versions per user or per project and switch between them often. For one newer interpreter on Ubuntu LTS, Deadsnakes or a single source altinstall is usually simpler.
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