Ubuntu 26.04 ships Python 3.14 and Ubuntu 24.04 ships Python 3.12, and neither can install some libraries pinned for the 3.11 era. On our bench, pip install numpy==1.24.4 died on both system interpreters, while the same pin inside a Python 3.11 virtual environment pulled a ready wheel and finished in 3.9 seconds. That gap is the whole reason to install Python 3.11 on Ubuntu next to the default interpreter instead of replacing it.
We installed it two ways: the deadsnakes PPA build (Python 3.11.18, tested November 2026 on Ubuntu 26.04, 24.04 and 22.04) went in within 30 seconds. A PGO plus LTO source build on 24.04 and 26.04 took about 20 minutes on 4 vCPUs. The steps below cover both, then pin an application and a systemd service to 3.11 without touching /usr/bin/python3. If you need the default Python of the release, pip basics or general venv background instead, the main Python on Ubuntu guide covers that ground. The two pages are not duplicates: that one covers a newer Python, while this one stays on 3.11 for code that cannot move yet.
deadsnakes PPA vs source build: measured results
Every figure in this table comes from fresh Google Cloud e2-standard-4 VMs (4 vCPU, 16 GB RAM) running the stock Ubuntu LTS images. The PPA rows are the apt-get install of python3.11, python3.11-venv and python3.11-dev; the source rows are a full optimized build of the same point release, installed with make altinstall.
| Measurement | Ubuntu 26.04 | Ubuntu 24.04 | Ubuntu 22.04 |
|---|---|---|---|
| Default python3 | 3.14 | 3.12 | 3.10 |
| deadsnakes download / disk | 31.5 MB / 87.5 MB | 35.4 MB / 99.8 MB | 28.3 MB / 92.8 MB |
| deadsnakes install (wall time) | 21.6 s | 29.9 s | 15.5 s |
| Source build deps download / disk | 105 MB / 341 MB | 101 MB / 326 MB | not tested |
./configure --enable-optimizations --with-lto | 38.1 s | 39.2 s | not tested |
make -j4 with PGO + LTO | 19m50s | 19m18s | not tested |
| Source install size in /usr/local/lib | 332 MB | 332 MB | not tested |
| numpy 1.24.4 in a 3.11 venv | installs, 3.9 s | installs, 4.5 s | not tested |
| numpy 1.24.4 on the system python3 | fails, setuptools.build_meta | fails, distutils | not tested |
On time alone the PPA wins by a factor of 40 to 55, so it is the right default for a workstation or a CI image. The source build earns its 20 minutes only when we need the interpreter under /usr/local, a custom configure flag, or a release the PPA has not packaged yet. Python 3.11 is in security-fix status until October 2027 per the Python release status page, which sets the shelf life of either install.
Step 1: Check the default Python on your Ubuntu release
Start by confirming the release and what /usr/bin/python3 points to. The system interpreter belongs to apt, cloud-init, netplan and command-not-found, so the goal is to add 3.11 beside it, never to swap it out. The Ubuntu archive carries no python3.11 package on 24.04 or 26.04, which is why the policy check shows no candidate before the PPA is added. The 22.04 VM showed the same thing: no python3.11 candidate until the PPA went in.
lsb_release -ds; python3 --version; ls -l /usr/bin/python3; apt-cache policy python3.11
On the 26.04 bench the system interpreter is 3.14 and apt has no candidate for 3.11 at all:
Ubuntu 26.04.1 LTS
Python 3.14.4
lrwxrwxrwx 1 root root 10 Mar 21 2026 /usr/bin/python3 -> python3.14
On 24.04 the VM printed Python 3.12.3 with the symlink on python3.12, and the 22.04 VM printed Python 3.10.12 on python3.10. Write down that target now, because it is the exact name needed to repair /usr/bin/python3 if anything repoints it later (Step 6). If you are still deciding which LTS to build on, our Ubuntu 26.04 vs 24.04 comparison lists the other toolchain changes between the two.
Step 2: Install Python 3.11 from the deadsnakes PPA
Maintainers of the deadsnakes PPA build older and newer CPython releases against each supported Ubuntu LTS. At the time of testing it published Python 3.11 for Resolute (26.04), Noble (24.04) and Jammy (22.04). We tested only those three releases. On anything older, move to a current LTS first, for example with our 24.04 to 26.04 upgrade walkthrough, or use the source build in Step 5.
sudo add-apt-repository -y ppa:deadsnakes/ppa
Read the warning in the PPA description before moving on. Modules from the Ubuntu archive are built for the system interpreter, so compiled extension modules from it will not load in a deadsnakes Python, and that shapes how pip is handled in Step 3. Check that apt now sees the new candidate:
apt-cache policy python3.11
Each candidate carries the release codename in its version suffix, and on our 26.04 VM apt read it from the amd64v3 index because the CPU supports x86-64-v3 (older CPUs show plain amd64):
python3.11:
Installed: (none)
Candidate: 3.11.18-1+resolute1
Version table:
3.11.18-1+resolute1 500
500 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu resolute/main amd64v3 Packages
The full bench session for this step, from the release check to the new candidate, looked like this on 26.04:

On 24.04 the suffix reads +noble1 and on 22.04 +jammy1. Install the interpreter with the two packages almost every real project needs:
- python3.11-venv provides the
venvmodule; without itpython3.11 -m venvfails. - python3.11-dev provides the headers that pip needs whenever a package has no wheel and must compile a C extension.
- Optional extras such as
python3.11-tk(tkinter) andpython3.11-gdbm(dbm.gnu) come from the same PPA when an app imports them.
sudo apt-get install -y python3.11 python3.11-venv python3.11-dev
apt also pulls python3.11-distutils and python3.11-lib2to3 as dependencies. Confirm that the new binary exists and that the system default did not move:
python3.11 --version; python3 --version; ls -l /usr/bin/python3 /usr/bin/python3.11
Two interpreters now sit side by side, with python3 still on the release default:

On 26.04 the install downloaded 31.5 MB and finished in 21.6 seconds. The 24.04 run printed Python 3.12.3 for python3 and took 29.9 seconds, and 22.04 kept Python 3.10.12 and took 15.5 seconds. In every case /usr/bin/python3 still pointed to the release default, which is the result we want.
Step 3: Add pip to the deadsnakes interpreter
A deadsnakes build ships without pip, and the Ubuntu python3-pip package belongs to the system interpreter, not to 3.11. The first python3.11 -m pip call therefore fails, and the bundled ensurepip module is the clean fix. It installs pip into the user site under ~/.local, so no sudo is involved.
python3.11 -m pip --version
python3.11 -m ensurepip
Our first command reported No module named pip, and the second installs the pip wheel bundled with the interpreter:

Two details in that output matter. The pip3.11 script lands in ~/.local/bin, which is not on PATH, so call it as python3.11 -m pip. More important, setuptools was found in /usr/lib/python3/dist-packages: the deadsnakes interpreter reads the Debian package directory of the system Python. We saw the same thing with requests:
python3.11 -m pip install requests
pip skipped the install entirely, because the system copy already satisfied it:
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.32.5)
[...]
A shared path is how a pure Python module from apt leaks into 3.11, and how a compiled one breaks it later, because the import succeeds until the extension loads. Treat user site installs as a quick test only. Anything you plan to run for real belongs in a virtual environment, since a venv isolates 3.11 from /usr/lib/python3/dist-packages and gives it its own pip.
Step 4: Pin an application to Python 3.11
Pinning means the virtual environment of the app is built from python3.11, so its python and pip are 3.11 no matter what python3 resolves to. Our test app pins numpy 1.24.4, a release with wheels up to CPython 3.11 and none for 3.12 or later, which makes it a fair stand-in for any legacy requirements file.
mkdir -p ~/legacy-app && cd ~/legacy-app
python3.11 -m venv .venv
.venv/bin/pip install numpy==1.24.4
pip picks the cp311 manylinux wheel, so nothing compiles:

Our install took 3.9 seconds on 26.04 and 4.5 seconds on 24.04, and the import check printed the 3.11 interpreter string with numpy 1.24.4. For contrast, we ran the same pin in a venv built from the 24.04 system Python 3.12:

With no wheel available, pip falls back to the source tarball, and its build backend imports distutils, which Python 3.12 removed. On 26.04 with 3.14 the failure moves one layer up to Cannot import 'setuptools.build_meta'. Either way the interpreter needs to change, not the package, so pinning 3.11 is cheaper than porting a legacy dependency tree under deadline.
Run a systemd service on the pinned interpreter
A service gets pinned the same way: point ExecStart at the python binary inside the venv rather than at python3. A bare python3 resolves through PATH, so it silently follows whatever the host default becomes. Create the unit file:
sudo vim /etc/systemd/system/legacy-app.service
Below is the unit we ran on the bench. Replace klinsmann with the account that owns the venv, and swap the inline -c test for the real entry point of your app:
[Unit]
Description=Legacy app pinned to Python 3.11
After=network.target
[Service]
User=klinsmann
WorkingDirectory=/home/klinsmann/legacy-app
ExecStart=/home/klinsmann/legacy-app/.venv/bin/python -c "import sys,time; print(sys.version, flush=True); time.sleep(3600)"
Restart=on-failure
[Install]
WantedBy=multi-user.target
Save the file, then reload systemd and start the unit:
sudo systemctl daemon-reload
sudo systemctl start legacy-app
systemctl status legacy-app --no-pager
sudo journalctl -u legacy-app --no-pager | tail -3
Our proof is the journal line, because the service prints the interpreter it actually runs on:

In that output the process tree shows the venv path and the journal shows a 3.11 build string, while python3 on the same host still answers 3.14. A later upgrade of the system Python cannot move this service, because nothing in the unit refers to it. Once your real entry point is in place, run sudo systemctl enable legacy-app so it starts at boot.
Step 5: Build Python 3.11 from source with PGO and LTO
Building from source is the path for releases the PPA does not cover, for servers where third-party PPAs are banned, or when an interpreter under /usr/local is wanted. We ran it on 26.04 and 24.04. Install the toolchain and the libraries behind the optional standard library modules first; every name below exists on both releases.
sudo apt-get install -y build-essential zlib1g-dev libncurses-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev liblzma-dev tk-dev uuid-dev pkg-config wget
apt pulled about 105 MB on 26.04 and 101 MB on 24.04. Next, find the newest 3.11 point release on python.org instead of hardcoding one, so the same commands keep working after the next security release:
PY311=$(curl -s https://www.python.org/ftp/python/ | grep -oE '"3\.11\.[0-9]+/"' | tr -d '"/' | sort -V | tail -1)
echo "${PY311}"
Our run printed the latest 3.11 release at the time of testing:
3.11.18
Download the tarball, print its SHA-256 and unpack it:
mkdir -p ~/src && cd ~/src
wget -q "https://www.python.org/ftp/python/${PY311}/Python-${PY311}.tgz"
sha256sum "Python-${PY311}.tgz"
tar -xf "Python-${PY311}.tgz" && cd "Python-${PY311}"
Our 26 MB tarball produced this hash on both VMs:
5f62711b12470fd435f83f1451c1b1ef4a179aebc715c716874b0967567d814e Python-3.11.18.tgz
Compare it with the SHA-256 checksum column on the python.org release page, which also links a GPG .asc signature and a Sigstore bundle for each file. Our value matched the published one, so the download was intact; stop here if yours differs, because a mismatch means a truncated or altered tarball. Now configure with profile guided optimization and link time optimization:
./configure --enable-optimizations --with-lto
Configure finished in 38.1 seconds on 26.04 and 39.2 seconds on 24.04. Without --enable-optimizations it ends with the hint please run ./configure --enable-optimizations, which is advice, not an error. Build with one job per core, then install with altinstall:
make -j$(nproc)
sudo make altinstall
Use altinstall, never plain install. The plain target also creates python3 and pip3 in /usr/local/bin, which sits before /usr/bin on PATH and would shadow the system interpreter for every user. The PGO build compiles the interpreter twice and runs a training workload from the test suite in between, which is where most of the 20 minutes goes:

Read the result from the bottom up. The binary is /usr/local/bin/python3.11, python3 still answers 3.14, and ssl, sqlite3, lzma, bz2, ctypes, readline and tkinter all import. Only _dbm and nis were skipped, both harmless for most apps (see the troubleshooting section). The build links whatever the release ships, so the source interpreter on 24.04 reported OpenSSL 3.0.13 and SQLite 3.45.1 instead.
Is the PGO build worth 20 minutes?
We built the same tree a second time with a plain ./configure on 26.04 and timed both with an identical timeit loop:
| Build on Ubuntu 26.04, 4 vCPU | make real time | make CPU (user) | sum(i*i for i in range(1_000_000)) |
|---|---|---|---|
Plain ./configure | 1m59.7s | 6m57.7s | 82.8 ms |
--enable-optimizations --with-lto | 19m50.5s | 40m24.5s | 71.5 ms |
Our optimized interpreter ran the loop about 14% faster for roughly ten times the build time. For a long-lived server interpreter that trade is worth it. For a throwaway CI image the plain build or the PPA package is the better call.
Step 6: Do not repoint /usr/bin/python3 to 3.11
Many older guides finish with update-alternatives to make 3.11 the default python3. We ran that on 26.04 to see what breaks, and apt broke on the next update. Ubuntu tooling imports compiled modules such as apt_pkg that are built only for the version of the system interpreter, so any other python3 cannot load them.

Three tools changed behaviour once python3 resolved to 3.11 on that VM:
- apt-get update fetched the indexes, then failed its post-invoke hook
/usr/lib/cnf-update-dbwithNo module named 'apt_pkg'and exited with an error. - command-not-found died with the same import error on every mistyped command.
- lsb_release still worked, which is why this mistake often goes unnoticed until the next apt run.
If a host is already in this state, remove the alternative and restore the symlink to the release default noted in Step 1:
sudo update-alternatives --remove-all python3
sudo ln -sf python3.14 /usr/bin/python3
Use python3.12 on 24.04 and python3.10 on 22.04. After the restore, sudo apt-get update completed cleanly on both test VMs. Call 3.11 by its full name or through a venv instead; a shell alias in ~/.bashrc is acceptable for an interactive login because scripts and system tools never read it.
Fix common Python 3.11 install errors on Ubuntu
Each error below appeared on our bench VMs, and the cause listed is the one we confirmed there, so you can match the message and skip the guesswork.
ModuleNotFoundError: No module named ‘distutils’
Expect it when a pinned package builds from source on Python 3.12 or newer, where distutils no longer exists. On 24.04 it is what numpy==1.24.4 printed under the system Python 3.12. Rebuild the venv from python3.11 as in Step 4; with a cp311 wheel available, nothing compiles at all.
BackendUnavailable: Cannot import ‘setuptools.build_meta’
Same root cause on 26.04: the build requirements of the old sdist cannot load on Python 3.14. numpy 1.24.4 published no wheels for anything newer than CPython 3.11, so pip has nothing prebuilt to fall back on. Use a 3.11 venv, or move the app to a numpy release that ships wheels for the newer Python.
/usr/bin/python3.11: No module named pip
Expected on the deadsnakes build, which ships no pip. Run python3.11 -m ensurepip for a user install, or better, create a venv with python3.11 -m venv, which bundles its own pip. Installing python3-pip from Ubuntu does not fix it, because that package targets the system interpreter.
The necessary bits to build these optional modules were not found: _dbm nis
Every source build on both releases printed this. nis is deprecated and builds only when libnsl-dev and libtirpc-dev are installed. _dbm wants the ndbm compatibility headers from libgdbm-compat-dev. dbm.gnu still built from libgdbm-dev, so only code that imports dbm.ndbm or nis directly is affected, which is rare; add those packages and rebuild if your app does.
Step 7: Keep Python 3.11 patched until October 2027
Python 3.11 now receives security fixes only, as source releases, and reaches end of life in October 2027. How the patches reach a host depends on the install path:
- deadsnakes: normal
sudo apt-get upgradepicks up new builds once the PPA publishes them. - Source build: rerun the
PY311detection, then configure, build andaltinstallagain over the old tree. Existing venvs keep working because they point at/usr/local/bin/python3.11. - Venvs: after a minor point upgrade nothing needs rebuilding; recreate them only when moving to a new minor version.
Treat October 2027 as the deadline for moving pinned apps to a supported interpreter. Our Python on Ubuntu 26.04 guide covers the 3.14 toolchain those apps will land on, and the Debian Python install guide covers the same side-by-side approach on Debian hosts.
Clear detailed explanation.
Thanks @Deepak,
Have a merry Christmas and a happy new year!
Hello.
After install the Python3.11, following your steps, the pip install only in Python3.10.6 (Native) and I can’t install pip for Python3.11.1.
The procedure below crachs my Linux:
sudo update-alternatives –install /usr/bin/python3 python3 /usr/local/bin/python3.11 2
sudo update-alternatives –install /usr/bin/python3 python3 /usr/bin/python3.10 1
sudo update-alternatives –config python3
Can you please share any solution?
Linux Mint 21.1
Python3.10.6 (Native)
We’ve updated the guide with correct steps of installing and using Pip 3.11.
The ppa has been deprecated, why still teaching us to use it?. Would be expecting a rework of this articlw with pgp. Thanks
PPA works. I don’t know what you mean by deprecated.
PPA is deprecated for Ubuntu 18. Compiling for 18 is needed and your instructions were clear and worked. Thank you!
We appreciate your feedback @John
Thank you so much dude ! Method 2 works really well ! I asked to GPT-4 how to install it, it said a bunch of crap !
Awesome!
This won’t install 3.11, 3.8 is max for 18.04.
not relevant for 18.04
There is a manual procedure provided.