Python 3.11 introduced faster startup, finer-grained error tracebacks, and exception groups that simplify async error handling. None of Ubuntu’s current LTS releases ship it in the default repositories, so to install Python 3.11 on Ubuntu you either add the Deadsnakes PPA (Ubuntu 24.04 and 22.04) or compile from source (Ubuntu 26.04).
The walkthrough below sets up the interpreter alongside Ubuntu’s system Python so apt and desktop tools stay intact. It also covers pip inside PEP 668-compliant virtual environments, version switching with update-alternatives, troubleshooting, and clean update or removal paths.
Install Python 3.11 on Ubuntu: Choose an Installation Method
Choose the installation method that matches your Ubuntu release. Ubuntu 24.04 LTS and Ubuntu 22.04 LTS can install Python 3.11 from the Deadsnakes PPA, while Ubuntu 26.04 LTS requires source compilation because the PPA does not currently publish a resolute repository.
Python 3.11 Package Availability on Ubuntu 26.04, 24.04, and 22.04
Ubuntu 22.04 LTS and 24.04 LTS do not ship a current Python 3.11 package in the default repositories, so the Deadsnakes PPA is the practical APT-based method for those releases. Ubuntu 26.04 LTS uses Python 3.13 by default and the Deadsnakes PPA currently returns a
Releasefile error forresolute.Never replace Ubuntu’s system
/usr/bin/python3interpreter with Python 3.11. Install Python 3.11 with versioned binaries, isolated prefixes, or virtual environments so apt and desktop tools continue using the distribution-managed interpreter.
Compare Python 3.11 Installation Options on Ubuntu
| Installation Option | Best For | Trade-offs |
|---|---|---|
| Deadsnakes PPA | Ubuntu 24.04 LTS and 22.04 LTS users who want pre-built packages integrated with apt | Community-maintained with no guaranteed security update timeline; not available for Ubuntu 26.04; production users must monitor CVEs independently |
| Compile from Source | Ubuntu 26.04 LTS (required), custom optimization requirements, air-gapped environments, or installations needing specific build flags like --enable-optimizations | Takes longer to build, you manage updates manually, requires build dependencies and periodic recompilation for security patches |
| Stick with Ubuntu’s Default Python | Users who do not specifically need Python 3.11; follow the Python 3.13 on Ubuntu guide for Ubuntu 26.04 LTS, Python 3.12 on Ubuntu for Ubuntu 24.04 LTS, or Python 3.10 on Ubuntu for Ubuntu 22.04 LTS | Does not provide Python 3.11; safest option for system scripts and tools that rely on the distribution’s default version |
Whichever method you choose, never replace the default /usr/bin/python3 interpreter. Ubuntu’s package manager, desktop tools, and system utilities depend on the version that ships with the distribution. If you are running Ubuntu inside WSL (Windows Subsystem for Linux), the same instructions apply.
Install Python 3.11 from the Deadsnakes PPA on Ubuntu 24.04 and 22.04
The Deadsnakes PPA provides Python 3.11 packages for Ubuntu 22.04 LTS and 24.04 LTS. Ubuntu 26.04 LTS users should skip to the source compilation section below.
Update Ubuntu Before Installing Python 3.11
Refresh package lists before adding the PPA so apt resolves dependencies correctly and uses current metadata.
sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease Reading package lists... Done
This guide uses
sudofor commands that need root privileges. If your account is not in the sudoers file yet, run the commands as root or follow the guide on how to add a new user to sudoers on Ubuntu.
Applying outstanding upgrades (sudo apt upgrade) before installing Python prevents dependency conflicts, especially on servers that have not been updated recently.
Import the Deadsnakes PPA for Python 3.11 on Ubuntu
Import the Deadsnakes Personal Package Archive (PPA), a community-maintained repository that publishes pre-built Python 3.11 packages for Ubuntu 22.04 and 24.04. If add-apt-repository is unavailable on minimal server images, install the helper first:
sudo apt install -y software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa -y
Refresh the package list so apt picks up the new PPA:
sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease Hit:2 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble InRelease Reading package lists... Done
The Deadsnakes PPA is community-maintained and does not guarantee timely security updates. For production systems that require predictable patch coverage, prefer Ubuntu’s supported default Python release for your Ubuntu version or use a source build with your own security monitoring and patch process.
Confirm that apt resolves python3.11 from the PPA before installing:
apt-cache policy python3.11
python3.11:
Installed: (none)
Candidate: 3.11.14-1+noble1
Version table:
3.11.14-1+noble1 500
500 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 Packages
On Ubuntu 22.04, the version suffix shows jammy instead of noble. Jammy may also show an older Ubuntu archive candidate (such as a release-candidate build), but the Deadsnakes package should appear as the preferred candidate. If the candidate remains (none), the PPA was not added correctly, apt metadata is stale, or you are running Ubuntu 26.04 where the PPA is not supported.
Install Python 3.11 Packages from the Deadsnakes PPA
Install Python 3.11 along with the virtual environment module and development headers:
sudo apt install python3.11 python3.11-venv python3.11-dev
Verify the installation:
python3.11 --version
Python 3.11.14
The exact patch version (3.11.14, 3.11.15, etc.) depends on when the Deadsnakes PPA last published updates. Verify that critical modules load correctly:
python3.11 -c "import ssl, sqlite3, bz2; print('Python 3.11 ready on Ubuntu')"
Python 3.11 ready on Ubuntu
Install Optional Python 3.11 Packages on Ubuntu
Install additional modules when your workflow demands debugging tools, GUI bindings, or compatibility layers. The core installation already includes python3.11-venv and python3.11-dev, so only add these packages if you need specific functionality:
Deadsnakes package splits differ by Ubuntu release. Current Ubuntu 24.04 (noble) builds provide more optional
python3.11-*packages than Ubuntu 22.04 (jammy). On jammy, packages likepython3.11-distutils,python3.11-lib2to3,python3.11-gdbm, andpython3.11-tkmay showCandidate: (none).Check package availability before installing optional modules with
apt-cache policy python3.11-distutils python3.11-tk python3.11-gdbm.
Debugging Packages for Python 3.11
python3.11-dbg provides debugging symbols for profiling, crash analysis, or gdb attachments.
sudo apt install python3.11-dbg
Python 3.11 Database and GUI Packages (Usually Noble Builds)
python3.11-gdbm provides GNU dbm bindings for lightweight key-value storage. This package is typically available in Ubuntu 24.04 Deadsnakes builds and may be unavailable on Ubuntu 22.04.
sudo apt install python3.11-gdbm
python3.11-tk installs Tkinter for GUI applications. This package is typically available in Ubuntu 24.04 Deadsnakes builds and may be unavailable on Ubuntu 22.04.
sudo apt install python3.11-tk
Python 3.11 distutils and Legacy Compatibility Packages on Ubuntu
python3.11-distutils ships the legacy Distutils build system still used by older setup.py scripts. It is commonly available on Ubuntu 24.04 Deadsnakes builds and may be missing on Ubuntu 22.04.
sudo apt install python3.11-distutils
python3.11-lib2to3 installs modernization tools for porting Python 2 code to Python 3. This module is deprecated and removed in Python 3.13, and the package is commonly available on Ubuntu 24.04 Deadsnakes builds but may be missing on Ubuntu 22.04.
sudo apt install python3.11-lib2to3
Only install python3.11-distutils or python3.11-lib2to3 when older build scripts require them. Modern projects rely on pip, setuptools, wheel, or pyproject.toml-based tooling instead.
Install a Common Python 3.11 Optional Package Set
Install a commonly used optional set that works across both Ubuntu 24.04 and 22.04 Deadsnakes builds. The python3.11-full meta-package pulls in a broader standard-library set, and python3.11-dbg adds debugging symbols. Package contents still vary by Ubuntu release and Deadsnakes build availability:
sudo apt install python3.11-dbg python3.11-full
Compile Python 3.11 from Source on Ubuntu (Required for Ubuntu 26.04)
Compile Python 3.11 manually when the Deadsnakes PPA is unavailable (Ubuntu 26.04 LTS), when you need custom optimization flags, or when you want an independent upgrade cycle. Source builds install alongside Ubuntu’s system Python without overwriting /usr/bin/python3. Ubuntu 26.04 users must use this method because the Deadsnakes PPA does not currently publish packages for that release.
Download the Python 3.11 Source Tarball on Ubuntu
Download the latest 3.11.x release directly from python.org into a dedicated build directory. The commands below automatically detect the newest patch version and extract it.
If a minimal Ubuntu server image returns curl: command not found or wget: command not found, install the download tools first with sudo apt install curl wget, then continue. Readers who want command syntax help can use the wget command examples guide and the cURL command in Linux guide.
mkdir -p "$HOME/python3.11-build"
cd "$HOME/python3.11-build"
VERSION=$(curl -s https://www.python.org/ftp/python/ | grep -oP '3\.11\.[0-9]+' | sort -V | tail -1)
echo "$VERSION"
wget "https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tar.xz"
tar -xf "Python-${VERSION}.tar.xz"
cd "Python-${VERSION}"
3.11.14
If you prefer to download a specific version manually, check the Python.org downloads page for available 3.11.x releases and replace the commands above with explicit version numbers (for example,
wget https://www.python.org/ftp/python/3.11.14/Python-3.11.14.tar.xz).
Verify the Python 3.11 Source Download (Optional)
Python.org provides GPG signatures for release tarballs. Verifying the signature confirms you downloaded an authentic, untampered file. If gpg is missing on a minimal Ubuntu install, install it with sudo apt install gnupg first. Python release manager signing keys can rotate between patch releases, so verify the signer fingerprint on the Python release page for your chosen ${VERSION} before importing a key. The example below uses the current Python 3.11.14 signer key:
gpg --keyserver hkps://keys.openpgp.org --recv-keys CFDCA245B1043CF2A5F97865FFE87404168BD847
Next, download the signature file for your version and verify the tarball:
wget "https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tar.xz.asc"
gpg --verify "Python-${VERSION}.tar.xz.asc" "Python-${VERSION}.tar.xz"
If you downloaded a specific version manually instead of using the automatic detection, replace
${VERSION}with the actual version number in both commands (for example,wget https://www.python.org/ftp/python/3.11.14/Python-3.11.14.tar.xz.asc).
If verification succeeds, gpg prints a Good signature from ... line. The signer name may differ from one Python 3.11.x release to another because release managers rotate keys. A warning about the key not being certified is normal when you have not personally signed the key. If verification fails, delete the tarball and re-download it.
Install Python 3.11 Build Dependencies on Ubuntu
Install the libraries required for SSL, compression, readline, Tk, and UUID support before compiling. The build-essential meta-package provides the GCC compiler on Ubuntu along with make and core build tools:
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev \
libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev liblzma-dev uuid-dev \
tk-dev pkg-config make
These package names work on Ubuntu 22.04 LTS, 24.04 LTS, and 26.04 LTS, so the same command works regardless of which release you are compiling on.
Configure and Build Python 3.11 on Ubuntu
Compile Python 3.11 with optimization flags. The following example installs under /usr/local/python3.11 to avoid overwriting your system interpreter. --enable-optimizations enables profile-guided optimization (PGO), --with-lto enables link-time optimization, and --prefix sets a custom install path so the build stays separate from system Python:
./configure --enable-optimizations --with-lto --with-ensurepip=install --prefix=/usr/local/python3.11
make -j"$(nproc)"
sudo make altinstall
Result: SUCCESS Successfully installed pip-24.0 setuptools-79.0.1
Using make altinstall instead of make install keeps /usr/bin/python3 untouched while adding /usr/local/python3.11/bin/python3.11.
Register Libraries and Test the Python 3.11 Build on Ubuntu
Point the dynamic linker at the custom installation, reload the cache, and create a convenience symlink so python3.11 works from any directory:
echo '/usr/local/python3.11/lib' | sudo tee /etc/ld.so.conf.d/python3.11.conf
sudo ldconfig
sudo ln -s /usr/local/python3.11/bin/python3.11 /usr/local/bin/python3.11
Verify the build and confirm critical modules load correctly:
python3.11 --version
python3.11 -c "import ssl, sqlite3, bz2; print('Source build is healthy')"
Python 3.11.14 Source build is healthy
If the second command fails, reinstall the missing -dev packages, rerun ./configure, and rebuild the installation.
Install Pip for Python 3.11 on Ubuntu
APT-installed Python 3.11 builds on Ubuntu typically do not include pip by default, so choose a pip setup method before installing third-party packages. Source builds in this guide use --with-ensurepip=install, but many readers still prefer a virtual environment workflow for consistency.
Choose a Python 3.11 Pip Installation Method on Ubuntu
You have multiple options for installing pip for Python 3.11. Debian and Ubuntu disable python3.11 -m ensurepip on many system interpreters to protect apt-managed files, so pip does not always appear automatically after installing Python 3.11 from APT. The safest approach is a virtual environment, which injects pip into an isolated directory without touching system paths. For Ubuntu’s default pip package workflow, see the Python pip guide for Ubuntu.
Install Pip in a Python 3.11 Virtual Environment (Recommended)
Ensure the virtual environment module is present (it was included in the earlier installation command). Create an isolated environment so pip installs alongside Python 3.11 without writing to system directories:
sudo apt install python3.11-venv
python3.11 -m venv ~/venvs/py311
source ~/venvs/py311/bin/activate
python -m pip --version
pip 24.x from /home/USER/venvs/py311/lib/python3.11/site-packages/pip (python 3.11)
This approach avoids the externally-managed environment restriction and keeps pip upgrades contained to the environment. Reactivate the environment for each project before installing packages.
If you also need pip for Ubuntu’s default Python, install python3-pip. It manages pip for the system interpreter only and does not add pip to Python 3.11 without using a virtual environment.
Bootstrap Python 3.11 pip with get-pip.py
Alternatively, for air-gapped systems or custom builds, download the latest bootstrap script and execute it with Python 3.11. Run this inside a virtual environment to avoid writing into system-managed locations. If you run it outside a venv, Ubuntu 24.04 and newer require --break-system-packages, which is risky on production machines.
wget https://bootstrap.pypa.io/get-pip.py
python3.11 get-pip.py
rm get-pip.py
This approach installs pip, setuptools, and wheel side by side. Keep the script up to date whenever you rerun the procedure.
Manage Packages with python3.11 -m pip on Ubuntu
Once pip is installed, always call pip through the desired interpreter to avoid cross-version confusion:
python3.11 -m pip install package_name
python3.11 -m pip install --upgrade package_name
python3.11 -m pip uninstall package_name
Replace package_name with libraries such as numpy, fastapi, or django. Using python3.11 -m pip keeps dependency management isolated from the system interpreter.
Ubuntu 24.04, 26.04, and future Ubuntu releases mark the system Python as “externally managed” (PEP 668). If you run
python3.11 -m pip install <package>against the base interpreter, pip usually fails unless you use a virtual environment or pass--break-system-packages.Use
--break-system-packagesonly in disposable development VMs or containers. It bypasses apt protections and can break system tools, future package upgrades, or shared environments. The recommended approach is a virtual environment per project.
Work in Python 3.11 Virtual Environments on Ubuntu
Virtual environments prevent package conflicts between projects by providing isolated site-packages directories. For comprehensive coverage of virtual environment workflows, see the dedicated Python virtual environment guide.
Create a Python 3.11 Virtual Environment
First, create a dedicated directory for your environments (for example ~/venvs) and provision a new one with python3.11:
python3.11 -m venv ~/venvs/py311
Replace ~/venvs/py311 with any path meaningful to your workflow.
Activate a Python 3.11 Virtual Environment on Ubuntu
Next, activate the environment so your shell points python and pip to the local installation:
source ~/venvs/py311/bin/activate
(py311) user@ubuntu:~$
The prompt changes to include the environment name, indicating successful activation. Install packages as needed while the environment remains active.
Deactivate the Python 3.11 Virtual Environment
When finished, exit the virtual environment by running:
deactivate
The shell returns to the system Python context, ensuring new sessions do not inherit the environment accidentally.
Switch Between Python Versions on Ubuntu
Use the update-alternatives framework only when you need the unversioned python command to point at a different interpreter. Keep calling python3.11 directly for most workflows and leave /usr/bin/python3 untouched so apt and system tools continue to function. Only register interpreters that are actually installed; delete lines for versions you do not have.
Register Python Versions with update-alternatives
The priority numbers (3, 4) determine automatic selection when in auto mode; higher numbers take precedence.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 4
Configure the Default python Command on Ubuntu
After registering each interpreter, select the default:
sudo update-alternatives --config python
Verify the selected interpreter after leaving the menu:
python --version
Python 3.11.14
Only adjust
/usr/bin/python(the unversioned python command, originally a Python 2 shim for legacy scripts). Leave/usr/bin/python3at the system default to avoid breaking apt, cloud-init, or other distribution utilities that depend on Ubuntu’s shipped interpreter.
Troubleshooting Common Python 3.11 Installation Issues
Python 3.11 Source Build Missing Modules After Compilation
Python can finish compiling even when optional development headers are missing, but modules like _ssl, _bz2, or _sqlite3 may be unavailable afterward. Check the configure output for disabled modules before rerunning the build:
./configure --enable-optimizations --with-ensurepip=install --prefix=/usr/local/python3.11 2>&1 | grep "disabled"
checking for stdlib extension module _tkinter... missing checking for stdlib extension module _ssl... missing
Install the matching -dev packages, then rerun ./configure, make, and sudo make altinstall. Verify the rebuilt interpreter loads the modules successfully:
python3.11 -c "import ssl, sqlite3, bz2; print('Module checks passed')"
Module checks passed
Python 3.11 Source Build Fails with “Disk quota exceeded”
Source builds can fail early during ./configure or later during compilation when the build directory hits a user or project quota, even if the filesystem still has free space.
./config.guess: line 125: echo: write error: Disk quota exceeded cat: -: EDQUOT: Quota exceeded configure: error: C compiler cannot create executables
Check free space and inode usage first, then clean old build directories or move the source tree to a location with more quota:
df -h /usr/local
df -ih /usr/local
rm -rf "$HOME/python3.11-build/Python-"*
If the error persists on a managed VM, use a user-owned build directory with more quota or ask the VM owner to increase the quota before retrying the source build.
Python 3.11 Shared Library Linking Error on Ubuntu
When running python3.11 after source compilation, you may encounter an error stating error while loading shared libraries: libpython3.11.so.1.0: cannot open shared object file. This happens when the dynamic linker cannot locate the Python shared library because it was installed outside standard library paths.
python3.11: error while loading shared libraries: libpython3.11.so.1.0: cannot open shared object file: No such file or directory
To resolve this, first verify the library exists:
find /usr/local -name "libpython3.11.so*"
/usr/local/python3.11/lib/libpython3.11.so.1.0
Then update the linker cache with the correct path. If you installed to the default prefix used in this guide, use:
sudo ldconfig /usr/local/python3.11/lib
Alternatively, add the library path to your environment permanently by creating a configuration file:
echo "/usr/local/python3.11/lib" | sudo tee /etc/ld.so.conf.d/python3.11.conf
sudo ldconfig
Verify the fix by running the version command again:
python3.11 --version
Python 3.11.14
Python 3.11 pip “externally-managed-environment” on Ubuntu 24.04 and 26.04
On Ubuntu 24.04, 26.04, and future releases, running python3.11 -m pip install package-name may fail with an “externally-managed-environment” error per PEP 668. Ubuntu marks the system Python as externally managed to prevent conflicts between apt-installed packages and pip-installed packages.
error: externally-managed-environment This environment is externally managed
The recommended solution is creating a virtual environment for each project:
python3.11 -m venv myproject_env
source myproject_env/bin/activate
pip install package-name
Verify that pip is now working inside the virtual environment:
pip --version
pip 24.x from /home/USER/myproject_env/lib/python3.11/site-packages/pip (python 3.11)
Alternatively, use --break-system-packages to bypass the restriction for short-lived test systems only. This writes into apt-managed paths and can cause upgrade or dependency conflicts on production hosts:
python3.11 -m pip install --break-system-packages package-name
Unable to Locate Package python3.11 on Ubuntu
The E: Unable to locate package python3.11 error (or variants like unable to locate package python3.11-dev) usually means apt is searching the wrong repository set for your Ubuntu release. On Ubuntu 24.04 and 22.04, add the Deadsnakes PPA and refresh apt metadata. On Ubuntu 26.04, the Deadsnakes PPA currently does not publish a resolute repository, so you must use the source-build method.
E: Unable to locate package python3.11
Check your Ubuntu codename and the package candidate before retrying:
lsb_release -cs
apt-cache policy python3.11
noble python3.11: Candidate: 3.11.14-1+noble1
If apt-cache policy python3.11 prints no output on Ubuntu 26.04, skip the PPA method and continue with source compilation. On Ubuntu 22.04, some optional split packages may still show Candidate: (none) even after the PPA is added; install the core packages and use python3.11-full when you need a broader standard-library set.
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update
sudo apt install python3.11 python3.11-venv python3.11-dev
APT Breaks After Changing Ubuntu’s System Python 3 Symlink
If apt update or apt install starts failing after you installed Python 3.11, make sure you did not replace Ubuntu’s system /usr/bin/python3 symlink. Ubuntu package tools expect the distribution default Python version.
ls -la /usr/bin/python3
lrwxrwxrwx 1 root root 10 ... /usr/bin/python3 -> python3.12
If the symlink points to Python 3.11 instead of your release default, restore it and keep invoking Python 3.11 with python3.11:
sudo ln -sf /usr/bin/python3.12 /usr/bin/python3
Replace 3.12 with your Ubuntu release default if needed (Ubuntu 26.04 uses Python 3.13, Ubuntu 24.04 uses Python 3.12, and Ubuntu 22.04 uses Python 3.10).
Verify the symlink points back to the distro default before retrying apt commands:
ls -la /usr/bin/python3
lrwxrwxrwx 1 root root 10 ... /usr/bin/python3 -> python3.12
Python 3.11 Virtual Environment Creation Fails
Another common issue occurs when python3.11 -m venv fails with “ensurepip is not available” or similar errors, indicating the python3.11-venv package is missing. Install it explicitly:
The virtual environment was not created successfully because ensurepip is not available.
sudo apt install python3.11-venv
For source-compiled installations, ensure you configured with --with-ensurepip=install before running make. If you skipped this flag, bootstrap pip manually using the get-pip.py script as described in the pip installation section.
Verify virtual environment creation succeeds after installing the missing package:
python3.11 -m venv ~/venvs/py311-check
~/venvs/py311-check/bin/python --version
Python 3.11.14
Update or Remove Python 3.11 on Ubuntu
After installation, keep Python 3.11 patched just like any other package. Use apt for repository builds and manual cleanup for source installations.
Update Python 3.11 Packages on Ubuntu
sudo apt update
sudo apt install --only-upgrade python3.11 python3.11-venv python3.11-dev
Add any optional python3.11-* packages you installed to the --only-upgrade command if you want to update them in the same pass.
python3.11 --version
Python 3.11.14
Update a Source-Built Python 3.11 Installation on Ubuntu
Source-built installations do not update automatically. When a new Python 3.11.x patch release is available, recompile to apply security fixes. Before using the script below, install the build dependencies from the source-build section and confirm curl, wget, and a working compiler toolchain are already present.
#!/usr/bin/env bash
set -euo pipefail
# Installation paths used by this guide.
INSTALL_PREFIX="/usr/local/python3.11"
BUILD_DIR="/usr/local/src/python3.11-build"
PY311_BIN="$INSTALL_PREFIX/bin/python3.11"
# Detect the newest upstream Python 3.11.x release.
echo "Checking for latest Python 3.11 release..."
LATEST_VERSION=$(curl -s https://www.python.org/ftp/python/ | grep -oP '3\.11\.[0-9]+' | sort -V | tail -1)
if [ -z "$LATEST_VERSION" ]; then
echo "Could not detect the latest Python 3.11 release."
exit 1
fi
CURRENT_VERSION=""
if [ -x "$PY311_BIN" ]; then
CURRENT_VERSION=$("$PY311_BIN" --version | awk '{print $2}')
fi
echo "Current: ${CURRENT_VERSION:-not installed}"
echo "Latest: $LATEST_VERSION"
echo
if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
echo "Python 3.11 is already up to date."
exit 0
fi
# Prompt before rebuilding and installing a new release.
read -r -p "Update to Python $LATEST_VERSION? (y/n) " REPLY
if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then
echo "Update cancelled."
exit 0
fi
# Reuse a persistent build directory so cleanup is predictable.
sudo install -d -m 0755 "$BUILD_DIR"
sudo chown "$USER":"$USER" "$BUILD_DIR"
cd "$BUILD_DIR"
rm -rf Python-*
wget "https://www.python.org/ftp/python/${LATEST_VERSION}/Python-${LATEST_VERSION}.tar.xz"
tar -xf "Python-${LATEST_VERSION}.tar.xz"
rm -f "Python-${LATEST_VERSION}.tar.xz"
cd "Python-${LATEST_VERSION}"
echo "Configuring build..."
./configure --enable-optimizations --with-lto --with-ensurepip=install --prefix="$INSTALL_PREFIX"
# Build and install without replacing Ubuntu's system python3.
echo "Compiling Python 3.11 (this can take several minutes)..."
make -j"$(nproc)"
echo "Installing Python 3.11..."
sudo make altinstall
echo '/usr/local/python3.11/lib' | sudo tee /etc/ld.so.conf.d/python3.11.conf
sudo ldconfig
echo
echo "Update complete."
"$PY311_BIN" --version
Store this script at a predictable path such as ~/update-python311.sh, make it executable with chmod +x ~/update-python311.sh, and run it manually when you want to check for updates. The script compares your installed version with the latest upstream 3.11.x release, prompts for confirmation, then downloads, compiles, and installs the update.
Avoid automating source updates with cron. Compilation can fail because of missing dependencies, quota limits, or interrupted downloads, and source updates should be monitored while they run.
Checking for latest Python 3.11 release... Current: 3.11.13 Latest: 3.11.14 Update complete. Python 3.11.14
Remove Python 3.11 Packages on Ubuntu
If a project no longer needs Python 3.11, uninstall the packages and optional modules:
sudo apt remove --purge python3.11 python3.11-venv python3.11-dev
sudo apt autoremove
These commands remove apt-managed Python 3.11 packages only. Project directories and virtual environments (for example under ~/venvs) remain on disk, and you should review the apt autoremove package list before confirming on development systems.
Remove the Deadsnakes PPA from Ubuntu
Additionally, remove the Deadsnakes PPA if you no longer need any Deadsnakes Python packages:
sudo add-apt-repository --remove ppa:deadsnakes/ppa -y
sudo apt update
apt-cache policy python3.11
python3.11: Installed: (none) Candidate: (none)
On Ubuntu 22.04, apt may still show an older Ubuntu archive entry for python3.11 after removing the PPA. That is expected and is not the Deadsnakes package.
Clean Up Source-Compiled Python 3.11 Installations
For source-compiled installations, delete the installation directory, linker entry, and build directory. The source-build section in this article uses $HOME/python3.11-build, while the optional update script uses /usr/local/src/python3.11-build. Remove whichever build directory you used:
The following commands permanently delete the source-compiled Python installation, the optional convenience symlink, and the local build tree. This removes the interpreter and any pip-installed packages under
/usr/local/python3.11. Back up anything you need first.
sudo rm -f /usr/local/bin/python3.11
sudo rm -rf /usr/local/python3.11
sudo rm -f /etc/ld.so.conf.d/python3.11.conf
rm -rf "$HOME/python3.11-build"
sudo rm -rf /usr/local/src/python3.11-build
sudo ldconfig
If you used a custom prefix like --prefix=/opt/python3.11, simply remove that directory:
sudo rm -rf /opt/python3.11
sudo ldconfig
Remove Python 3.11 update-alternatives Entries
Finally, if you configured update-alternatives for Python version switching, remove the python3.11 entry:
sudo update-alternatives --remove python /usr/bin/python3.11
Verify the removal completed successfully:
sudo update-alternatives --list python
update-alternatives: error: no alternatives for python
Compare Python Versions on Ubuntu (Reference)
Compare Python Releases for Ubuntu
Use this reference section if you are deciding whether Python 3.11 fits your workload better than Ubuntu’s default Python version or newer community-packaged releases.
| Python Version | Availability on Ubuntu | Choose It When | Trade-offs |
|---|---|---|---|
| Python 3.8 | Deadsnakes PPA (22.04/24.04 only) or source build | Legacy applications pinned to EOL runtimes, transitional migrations, compatibility testing | Security fixes ended October 2024, limited upstream support, container isolation recommended |
| Python 3.10 | Ubuntu 22.04 LTS default, Deadsnakes PPA for 24.04, source build for 26.04 | Production fleets that prioritize long-term compatibility with older vendor SDKs | Older feature set, fewer interpreter improvements than 3.11+, and extra setup on newer Ubuntu releases |
| Python 3.11 | Deadsnakes PPA for 24.04/22.04; source build required for 26.04 | Projects that want a mature runtime with performance improvements over Python 3.10 and broad package compatibility | Not default on any supported Ubuntu LTS, community PPA support on 24.04/22.04, source maintenance required on 26.04 |
| Python 3.12 | Ubuntu 24.04 LTS default, Deadsnakes PPA for 22.04 | General-purpose development on Ubuntu 24.04 or projects targeting newer language features with stable distro integration | Ubuntu 22.04 requires a PPA; Ubuntu 26.04 has moved to Python 3.13 by default |
| Python 3.13 | Ubuntu 26.04 LTS default, Deadsnakes PPA for 24.04/22.04 | Teams adopting the current Ubuntu 26.04 default interpreter or validating newer language changes | Some third-party wheels may lag early releases; 24.04/22.04 depend on Deadsnakes packaging |
| Python 3.14 | Deadsnakes PPA for 24.04/22.04 as published; source builds for 26.04 | Early adopters benchmarking the newest interpreter and validating upcoming ecosystem support | Not in Ubuntu repositories, PPA refresh cadence may lag upstream, more package compatibility testing required |
When Python 3.11 Is a Good Fit on Ubuntu
Choose Python 3.11 when you need a mature release with broad third-party package support, better runtime performance than Python 3.10, and fewer compatibility surprises than very new interpreter releases. It remains a strong option for API services, data processing jobs, automation, and CI environments that need stable behavior across mixed Ubuntu LTS fleets.
Skip Python 3.11 when you want the Ubuntu default interpreter for long-lived system-managed hosts (Python 3.13 on Ubuntu 26.04, Python 3.12 on Ubuntu 24.04, Python 3.10 on Ubuntu 22.04), or when your organization has already standardized on a newer Python branch for feature or support lifecycle reasons.
Key Reasons to Choose Python 3.11 on Ubuntu
Python 3.11 remains a practical target on Ubuntu when you want a balance of speed, modern language features, and package ecosystem maturity:
- Faster runtime than Python 3.10 for many workloads: Python 3.11 includes interpreter optimizations that reduce overhead on common application paths without requiring code changes.
- Exception groups and
except*: Concurrency-heavy applications can handle grouped exceptions natively. - Built-in TOML parsing: The
tomllibmodule removes a common dependency for readingpyproject.tomland other TOML configuration files. - Mature package compatibility: Python 3.11 is widely supported by libraries and tools that may still be catching up to newer branches.
- Safe coexistence with Ubuntu defaults: Versioned binaries (
python3.11) and virtual environments let you add Python 3.11 without changing/usr/bin/python3.
Python 3.11 on Ubuntu FAQ
Ubuntu 24.04 and 22.04 need the Deadsnakes PPA plus apt update before python3.11 becomes installable. Ubuntu 26.04 does not currently have a supported Deadsnakes resolute repository for Python 3.11, so the source-build method is required.
Not as a current supported package on the Ubuntu releases covered here. Ubuntu 22.04, 24.04, and 26.04 use different default Python versions, so Python 3.11 is installed through the Deadsnakes PPA (24.04 and 22.04) or source compilation (26.04).
python3.11-distutils missing on Ubuntu 22.04 Deadsnakes?
Deadsnakes package splits differ by Ubuntu release. Current Noble (24.04) builds provide more optional python3.11-* packages than Jammy (22.04), so python3.11-distutils and similar packages may show Candidate: (none) on Ubuntu 22.04 even when the core python3.11 package is available.
This article focuses on Ubuntu 26.04, 24.04, and 22.04. If you still use Ubuntu 20.04, a source build is usually the safest path, but upgrading to a supported Ubuntu LTS is the better long-term option.
Ubuntu 24.04 and 26.04 implement PEP 668 for the system Python environment, so pip blocks direct installs into apt-managed directories. Use a virtual environment with python3.11 -m venv, or use --break-system-packages only if you accept the risk.
Yes. Both the Deadsnakes PPA and source-build methods work on WSL running Ubuntu 22.04 or 24.04. Run wsl --list --verbose in PowerShell to confirm your Ubuntu version before starting, then follow the matching section in this guide.
Conclusion
Python 3.11 is running side-by-side with Ubuntu’s default interpreter, and virtual environments keep project dependencies isolated from apt-managed packages. For broader Python tooling, install and configure pip on Ubuntu or set up Python virtual environments on Ubuntu for multi-project workflows.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>