How to Install Python 3.11 on Ubuntu 26.04, 24.04 and 22.04

Install Python 3.11 on Ubuntu 26.04, 24.04 and 22.04 using the Deadsnakes PPA, source builds, or virtual environments with pip support.

UpdatedPublished AuthorJoshua JamesRead time16 minGuide typeUbuntu

Install Python 3.11 on Ubuntu 26.04, 24.04, or 22.04 from the Deadsnakes PPA when you need broad wheel support, mature library compatibility, and an APT-managed interpreter alongside Ubuntu’s default Python.

The interpreter stays beside Ubuntu’s system Python, so apt, desktop tools, and release-managed packages continue using the distribution default. The same workflow covers troubleshooting, pip in virtual environments, WSL installs, source builds, updates, and removal without retargeting /usr/bin/python3.

Install Python 3.11 on Ubuntu

Choose the installation method that matches how you want Python maintained. Deadsnakes currently publishes Python 3.11 packages for Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS, while source compilation is best reserved for custom build flags, isolated prefixes, or environments where you manage Python security updates yourself.

Python 3.11 Package Availability on Ubuntu 26.04, 24.04, and 22.04

Ubuntu 26.04 LTS uses Python 3.14 by default, Ubuntu 24.04 LTS uses Python 3.12, and Ubuntu 22.04 LTS uses Python 3.10. Deadsnakes provides Python 3.11 as a separate APT-managed interpreter for all three supported LTS releases, so most readers should use the PPA path instead of compiling from source.

Never replace Ubuntu’s system /usr/bin/python3 interpreter 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 OptionRelease ScopeUpdate BehaviorBest FitTrade-offs
Deadsnakes PPAUbuntu 26.04, 24.04, and 22.04APT-managed updates from the PPAMost users who need Python 3.11 packages beside Ubuntu’s default PythonCommunity-maintained with no guaranteed security timeline; monitor Python security fixes and PPA update cadence
Compile from SourceCustom local prefix on any supported Ubuntu releaseManual rebuilds for each Python 3.11.x updateCustom prefixes, local patches, air-gapped systems, or build flags not provided by packagesTakes longer, requires build dependencies, and leaves update tracking to you
Stick with Ubuntu’s Default PythonPython 3.14 on 26.04, Python 3.12 on 24.04, Python 3.10 on 22.04Ubuntu package updatesSystems that do not specifically need Python 3.11; see Python 3.14 on Ubuntu, Python 3.12 on Ubuntu, or Python 3.10 on UbuntuDoes not provide Python 3.11; safest for tools that rely on the distribution default

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.

Ubuntu 20.04 left standard support in May 2025, so the commands here focus on Ubuntu 26.04, 24.04, and 22.04. If you still maintain Ubuntu 20.04 under a separate support arrangement, use an isolated source build or upgrade the host before adding new development runtimes.

Install Python 3.11 from the Deadsnakes PPA on Ubuntu

The Deadsnakes PPA provides current Python 3.11 packages for Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. This is the recommended install path when you want APT-managed packages instead of a manually maintained source build.

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

Commands that change packages or system paths use sudo. 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 26.04, 24.04, and 22.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

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 only when you also own the security monitoring and rebuild process.

Confirm that apt resolves python3.11 from the PPA before installing:

apt-cache policy python3.11
python3.11:
  Installed: (none)
  Candidate: 3.11.15-1+resolute1
  Version table:
     3.11.15-1+resolute1 500
        500 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu resolute/main amd64 Packages

The version suffix follows your Ubuntu codename: resolute1 on 26.04, noble1 on 24.04, and jammy1 on 22.04. If the candidate remains (none), the PPA was not added correctly, apt metadata is stale, or the PPA is temporarily unreachable from your mirror path.

Do not use packages.ubuntu.com as proof for these PPA packages. That index covers Ubuntu archive packages, while Deadsnakes packages are resolved through Launchpad PPA metadata and apt-cache policy after the PPA is enabled.

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.15

The exact patch version 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 26.04 (resolute) and 24.04 (noble) builds provide more optional python3.11-* packages than Ubuntu 22.04 (jammy). On jammy, packages like python3.11-distutils, python3.11-lib2to3, python3.11-gdbm, and python3.11-tk may show Candidate: (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

python3.11-gdbm provides GNU dbm bindings for lightweight key-value storage. This package is typically available in Ubuntu 26.04 and 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 26.04 and 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 26.04 and 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 26.04 and 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 Ubuntu 26.04, 24.04, and 22.04 Deadsnakes builds for the core debug and full packages. The python3.11-full meta-package pulls in a broader standard-library set, and python3.11-dbg adds debugging symbols. Optional split packages 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

Compile Python 3.11 manually when you need a custom prefix, local patches, or a security update process independent of the Deadsnakes PPA. Source builds install alongside Ubuntu’s system Python without overwriting /usr/bin/python3, but they do not receive APT updates.

Download the Python 3.11 Source Tarball on Ubuntu

Download the latest stable 3.11.x source release from python.org into a dedicated build directory. The command scopes detection to the stable releases section so pre-release folders do not become accidental install targets.

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" || exit
VERSION=$(curl -fsSL --compressed https://www.python.org/downloads/source/ | awk '/Stable Releases/ { stable=1; next } /Pre-releases/ { stable=0 } stable && !found && match($0, /Python 3\.11\.[0-9]+/) { print substr($0, RSTART + 7, RLENGTH - 7); found=1 }')
if [ -z "$VERSION" ]; then
  echo "Could not detect the latest Python 3.11 stable release."
  exit 1
fi
echo "$VERSION"
wget "https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tar.xz"
tar -xf "Python-${VERSION}.tar.xz"
cd "Python-${VERSION}" || exit

The command prints the resolved 3.11.x version before downloading the tarball. Confirm that value starts with 3.11. before continuing.

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.15/Python-3.11.15.tar.xz).

Verify the Python 3.11 Source Download (Optional)

Python.org provides GPG signatures for Python 3.11 source 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 release branches, so compare the signer against Python’s OpenPGP verification page for your chosen ${VERSION}. The example below uses the current Python 3.11 release manager 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.15/Python-3.11.15.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 curl wget gnupg xz-utils 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 under /usr/local/python3.11 to avoid overwriting your system interpreter. The standard release build is faster and less fragile than a profile-guided build on small VMs. Use PGO or LTO only after validating those flags on your own host.

./configure --with-ensurepip=install --prefix=/usr/local/python3.11
make -j"$(nproc)"
sudo make altinstall

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 under /usr/local/bin only if the source install did not already place python3.11 on your PATH:

printf '%s\n' '/usr/local/python3.11/lib' | sudo tee /etc/ld.so.conf.d/python3.11.conf >/dev/null
sudo ldconfig
if ! command -v python3.11 >/dev/null 2>&1; then
  sudo ln -s /usr/local/python3.11/bin/python3.11 /usr/local/bin/python3.11
fi

Verify the build and confirm critical modules load correctly:

python3.11 --version
python3.11 -c "import ssl, sqlite3, bz2, lzma; print('Source build is healthy')"
Python 3.11.15
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 a base-interpreter pip command for project work, so create a virtual environment before installing third-party packages. Source builds in this article use --with-ensurepip=install, but virtual environments remain the safest project workflow across all supported Ubuntu releases.

Choose a Python 3.11 Pip Installation Method on Ubuntu

You have multiple options for using pip with Python 3.11. Debian and Ubuntu disable ensurepip on many package-managed interpreters to protect apt-owned 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

The output should point inside ~/venvs/py311 and end with (python 3.11), confirming pip belongs to the virtual environment rather than Ubuntu’s base interpreter.

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

Use get-pip.py only for custom source builds, air-gapped staging, or disposable environments where the virtual environment workflow is not enough. Do not use it to force pip into Ubuntu’s package-managed default Python.

wget https://bootstrap.pypa.io/get-pip.py
/usr/local/python3.11/bin/python3.11 get-pip.py
rm get-pip.py

This approach installs pip, setuptools, and wheel for the source-built interpreter under the prefix used in the source build section. 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 26.04, 24.04, and future Ubuntu releases mark the system Python as “externally managed” (PEP 668). If pip reports externally-managed-environment, create a virtual environment instead of trying to write into the base interpreter.

Use --break-system-packages only 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.

Use Python 3.11 Without Changing Ubuntu’s Default Python

Keep Python 3.11 on versioned commands and project-specific paths. Ubuntu’s package manager and system utilities expect the release-owned /usr/bin/python3 interpreter, so do not use update-alternatives, manual symlinks, or copied binaries to make Python 3.11 the system default.

Call the Python 3.11 Binary Directly

Use python3.11 for scripts, module commands, and quick version checks:

python3.11 --version
python3.11 -m venv ~/venvs/py311

Use Explicit Paths for Services or Scripts

For service files, cron jobs, and shell scripts, point to the interpreter you installed instead of changing a global default. PPA installs normally use /usr/bin/python3.11, while the source-build path in this article uses /usr/local/python3.11/bin/python3.11.

command -v python3.11
/usr/bin/python3.11 --version
/usr/bin/python3.11
Python 3.11.15

Source-built systems may return the custom prefix instead:

/usr/local/python3.11/bin/python3.11 --version
Python 3.11.15

Leave both /usr/bin/python3 and package-owned default Python packages alone. If a project needs Python 3.11, use a virtual environment, an explicit shebang such as #!/usr/bin/env python3.11, or a service-level ExecStart= path that names Python 3.11 directly.

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 --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, lzma; 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 source-build prefix, 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.15

Python 3.11 pip “externally-managed-environment” on Ubuntu 26.04 and 24.04

On Ubuntu 26.04, 24.04, and future releases, running pip against Ubuntu’s base interpreter can 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

The output should point inside myproject_env and end with (python 3.11).

Use --break-system-packages only in disposable environments where you accept the risk of writing into apt-managed paths. This 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 or the PPA source is missing or disabled. Deadsnakes currently publishes Python 3.11 for Ubuntu 26.04, 24.04, and 22.04, so check the codename, confirm the PPA source, and refresh apt metadata before retrying.

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
resolute
python3.11:
  Candidate: 3.11.15-1+resolute1

If apt-cache policy python3.11 shows Candidate: (none) on Ubuntu 26.04, 24.04, or 22.04, confirm that the PPA source matches your codename and rerun sudo apt update. 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 Replacing Ubuntu’s System Python 3

If apt update, apt install, add-apt-repository, or desktop update tools start failing after you installed Python 3.11, check whether Ubuntu’s system /usr/bin/python3 still points to the package-managed interpreter for your release.

readlink -f /usr/bin/python3
dpkg -S "$(readlink -f /usr/bin/python3)"
/usr/bin/python3.14
python3.14-minimal: /usr/bin/python3.14

The expected target differs by release: Ubuntu 26.04 uses Python 3.14, Ubuntu 24.04 uses Python 3.12, and Ubuntu 22.04 uses Python 3.10. If the path points to Python 3.11 or to a custom source tree, reinstall the packages that own Ubuntu’s Python runtime instead of adding another switcher:

sudo apt install --reinstall python3-minimal python3-apt python3-distro-info command-not-found
sudo apt --fix-broken install

If APT itself cannot run because the interpreter was overwritten, recover from a root shell or live environment and reinstall the release-owned Python packages before returning to normal package management.

Verify the path points back to the distro default before retrying apt commands:

readlink -f /usr/bin/python3
/usr/bin/python3.14

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.15

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.15

Update a Source-Built Python 3.11 Installation on Ubuntu

Source-built installations do not update through apt. Check the installed version against the latest Python 3.11.x source release, then rebuild only when the upstream patch level is newer. The workflow below keeps the custom prefix under /usr/local/python3.11 and still uses make altinstall, so it does not replace Ubuntu’s default /usr/bin/python3.

Check Source-Built Python 3.11 Versions

First, confirm the version currently installed in the source-build prefix:

/usr/local/python3.11/bin/python3.11 --version
Python 3.11.15

Then resolve the newest stable Python 3.11.x source release from Python.org. The command prints a single version string:

curl -fsSL --compressed https://www.python.org/downloads/source/ | awk '/Stable Releases/ { stable=1; next } /Pre-releases/ { stable=0 } stable && !found && match($0, /Python 3\.11\.[0-9]+/) { print substr($0, RSTART + 7, RLENGTH - 7); found=1 }'
3.11.15

If both versions match, no rebuild is needed. If the Python.org version is newer, use the helper below after confirming the source-build dependencies, curl, wget, and compiler tools are installed.

Create the Python 3.11 Source Update Helper

Create the helper under ~/.local/bin. It checks the current and latest versions, asks for confirmation, rebuilds in $HOME/python3.11-build, installs with make altinstall, updates the linker cache, and finishes with version and module checks:

mkdir -p "$HOME/.local/bin"
tee "$HOME/.local/bin/update-python311" >/dev/null <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

# Installation paths used in the source-build section.
INSTALL_PREFIX="/usr/local/python3.11"
BUILD_DIR="$HOME/python3.11-build"
PY311_BIN="$INSTALL_PREFIX/bin/python3.11"

# Detect the newest stable upstream Python 3.11.x source release.
echo "Checking for latest Python 3.11 release..."
LATEST_VERSION=$(curl -fsSL --compressed https://www.python.org/downloads/source/ | awk '/Stable Releases/ { stable=1; next } /Pre-releases/ { stable=0 } stable && !found && match($0, /Python 3\.11\.[0-9]+/) { print substr($0, RSTART + 7, RLENGTH - 7); found=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.
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR" || exit

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}" || exit

echo "Configuring build..."
./configure --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
printf '%s\n' "$INSTALL_PREFIX/lib" | sudo tee /etc/ld.so.conf.d/python3.11.conf >/dev/null
sudo ldconfig

echo
echo "Update complete."
"$PY311_BIN" --version
"$PY311_BIN" -c "import ssl, sqlite3, bz2, lzma; print('Module checks passed')"
EOF
chmod +x "$HOME/.local/bin/update-python311"

Run the helper manually when you want to check for source updates:

"$HOME/.local/bin/update-python311"

When Python 3.11 is already current, the helper exits before downloading or compiling anything:

Checking for latest Python 3.11 release...
Current: 3.11.15
Latest:  3.11.15

Python 3.11 is already up to date.

For example, an update from Python 3.11.14 to Python 3.11.15 starts with this comparison and prompt:

Checking for latest Python 3.11 release...
Current: 3.11.14
Latest:  3.11.15

Update to Python 3.11.15? (y/n)

After you answer y, the helper downloads the source tarball, configures the build, compiles Python, installs it into the custom prefix, and runs the final checks:

Configuring build...
Compiling Python 3.11 (this can take several minutes)...
Installing Python 3.11...

Update complete.
Python 3.11.15
Module checks passed

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.

Remove Python 3.11 Packages on Ubuntu

If a project no longer needs Python 3.11, uninstall the packages and optional modules you installed from the PPA:

sudo apt remove python3.11 python3.11-venv python3.11-dev

This command removes apt-managed Python 3.11 packages only. Project directories and virtual environments (for example under ~/venvs) remain on disk. Preview any automatic dependency cleanup separately before running it:

sudo apt autoremove --dry-run

Review the dry-run output before running a real autoremove 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)

If another repository still provides python3.11, check the version table and confirm the removed Deadsnakes source no longer appears as a candidate source.

Clean Up Source-Compiled Python 3.11 Installations

For source-compiled installations, delete the installation directory, linker entry, optional updater, and build directory. The source-build and update sections use $HOME/python3.11-build as the reusable source workspace.

The following commands permanently delete the source-compiled Python installation, the optional convenience symlink, updater helper, and 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
rm -f "$HOME/.local/bin/update-python311"
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 ldconfig

If you used a custom prefix like --prefix=/opt/python3.11, simply remove that directory:

sudo rm -rf /opt/python3.11
sudo ldconfig

Verify Python 3.11 Removal on Ubuntu

Confirm no APT-managed Python 3.11 packages remain installed, then check that Ubuntu’s default interpreter still belongs to the release-owned Python package:

dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' 'python3.11*' 2>/dev/null | grep '^ii' || echo "No Python 3.11 packages installed"
readlink -f /usr/bin/python3
No Python 3.11 packages installed
/usr/bin/python3.14

The default path example above is from Ubuntu 26.04. Ubuntu 24.04 should point to Python 3.12, and Ubuntu 22.04 should point to Python 3.10.

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 VersionAvailability on UbuntuChoose It WhenTrade-offs
Python 3.8Legacy Deadsnakes/source workflows onlyLegacy applications pinned to EOL runtimes, transitional migrations, compatibility testingSecurity fixes ended October 2024, limited upstream support, container isolation recommended
Python 3.10Ubuntu 22.04 LTS default; Deadsnakes or source on newer releases when neededProduction fleets that prioritize long-term compatibility with older vendor SDKsOlder feature set, fewer interpreter improvements than 3.11+, and extra setup on newer Ubuntu releases
Python 3.11Deadsnakes PPA for Ubuntu 26.04/24.04/22.04; source build optionalProjects that want a mature runtime with performance improvements over Python 3.10 and broad package compatibilityNot default on supported Ubuntu LTS releases; community PPA support or manual source maintenance required
Python 3.12Ubuntu 24.04 LTS default; Deadsnakes/source workflows on other releases when neededGeneral-purpose development on Ubuntu 24.04 or projects targeting newer language features with stable distro integrationUbuntu 22.04 requires an alternate package path; Ubuntu 26.04 has moved to Python 3.14 by default
Python 3.13Alternate Deadsnakes/source workflows for projects pinned to the 3.13 branchTeams validating newer optimizations or compatibility before moving to Python 3.14Not the default on the supported LTS set in this article; package availability and wheel support need verification
Python 3.14Ubuntu 26.04 LTS default; Deadsnakes/source workflows on older supported LTS releases when neededUbuntu 26.04 users who want the release-owned default interpreter or teams adopting the newest branchDefault only on 26.04; older LTS releases need alternate packaging and package compatibility testing

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.14 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 tomllib module removes a common dependency for reading pyproject.toml and 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.

Conclusion

Python 3.11 is available on Ubuntu as a separate interpreter through the Deadsnakes PPA or a manually maintained source prefix, while Ubuntu’s default python3 remains package-managed. For broader tooling, install and configure pip on Ubuntu or set up Python virtual environments on Ubuntu for multi-project workflows.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: