How to Install Python 3.10 on Ubuntu Linux

Python 3.10 receives upstream security updates through October 2026, making it a dependable target for production workloads that cannot yet adopt Python 3.11 or 3.12. It ships as the default interpreter on Ubuntu 22.04 LTS and installs easily through the Deadsnakes Personal Package Archive (PPA) on Ubuntu 24.04 LTS and newer releases. Pattern matching simplifies complex conditional logic, improved error tracebacks pinpoint exact syntax issues, and union type syntax modernizes type hints without forcing teams to rewrite validated codebases.

This guide covers installing Python 3.10 from Ubuntu repositories, the Deadsnakes PPA, or custom source builds, then shows how to add development headers, configure pip safely, manage virtual environments, switch between interpreters without touching the system Python, and cleanly remove Python 3.10 when a project upgrades.

When to Choose Python 3.10 Over Newer Versions

Compare Python Releases for Ubuntu

Ubuntu maintains multiple Python streams across LTS releases and community PPAs. Use the following comparison to determine when Python 3.10 provides the right balance of stability, support, and feature coverage.

Python VersionAvailability on UbuntuChoose It WhenTrade-offs
Python 3.8Deadsnakes PPA or source build 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 PPA for 24.04 LTS+Production fleets that require LTS security coverage through 2026, tools expecting pattern matching or 3.10-specific ABIReceives fewer new features, Ubuntu 24.04+ users must import PPA, some libraries now target 3.11+
Python 3.11Deadsnakes PPA (where available) or source buildPerformance-focused workloads and teams that want newer language/runtime features (for example exception groups and TOML support)Not the default interpreter on Ubuntu LTS releases, some vendor SDKs still validate primarily against 3.10
Python 3.12Ubuntu 24.04 LTS default, Deadsnakes PPA for 22.04 LTSNew deployments, developers targeting f-string upgrades, continued language/runtime improvementsNewer runtime may expose compatibility gaps in older modules, Ubuntu 22.04 LTS systems may rely on Deadsnakes PPA
Python 3.13Deadsnakes PPA (where published) or source buildAdopting the latest typing and startup improvements, validating newer interpreter behavior, preparing for future upgradesNot in Ubuntu repositories, community packages lack guaranteed security SLAs, some third-party wheels may lag initial releases
Python 3.14Deadsnakes PPA (where published) or source buildEarly adopter testing and benchmarking, validating the newest runtime features as they landNot in Ubuntu repositories, PPA refresh cadence may lag security fixes, third-party wheels can trail initial releases

Stick with Python 3.10 when you prioritize predictable LTS maintenance, when vendor tools certify only against Ubuntu 22.04 LTS defaults, or when your automation pipeline already consumes 3.10 wheel builds. Install a newer release for greenfield projects or workloads that benefit from the performance and syntax enhancements in 3.11, 3.12, 3.13, or 3.14.

Key Reasons to Keep Python 3.10

Even with newer interpreters available, Python 3.10 remains the safer choice for:

  • Vendor compatibility: Enterprise software such as Ansible playbooks, ERP agents, and data science pipelines often certify against 3.10 because it ships with Ubuntu 22.04 LTS.
  • LTS security cadence: Canonical provides Extended Security Maintenance for Ubuntu 22.04 LTS (Jammy Jellyfish) through mid-2032, so python3.10 receives patched packages even after upstream EOL.
  • Predictable ABI stability: Wheel builds that expose native extensions (for example psycopg or numpy compiled with OpenBLAS) already target CPython 3.10 abi3 tags.
  • Long-lived infrastructure automation: Bootstrapping scripts, cloud-init snippets, and cluster orchestration tooling frequently embed python3.10 paths that you do not want to rewrite mid-release.

Choose Your Python 3.10 Installation Method

Pick the installation method that matches your Ubuntu release and deployment requirements. The table below helps you decide which approach delivers the most reliable updates and compatibility.

MethodChannelVersionUpdatesBest For
APT (Ubuntu 22.04 repos)Ubuntu ReposUbuntu-maintained 3.10.x (LTS-patched)Automatic via apt upgradeUbuntu 22.04 LTS systems (recommended)
APT (Deadsnakes PPA)Deadsnakes PPA3.10.x (community-built)Automatic via apt upgrade (PPA cadence)Ubuntu 24.04 LTS+ when you need Python 3.10
Build from sourcePython.org SourceYou choose (latest 3.10.x recommended)Manual rebuild for updatesCustom prefixes, compile flags, or isolated installs

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.

Install Python 3.10 on Ubuntu

The exact steps depend on whether your system ships python3.10 through the official repositories (Ubuntu 22.04 LTS and derivatives) or needs the Deadsnakes PPA (Ubuntu 24.04 LTS and newer). Start by refreshing the package index so apt uses the latest metadata.

This guide supports Ubuntu 22.04 LTS and 24.04 LTS installations. On Ubuntu 22.04 LTS, Python 3.10 is available in the official repositories; on Ubuntu 24.04 LTS, you typically install Python 3.10 from the Deadsnakes PPA or compile from source. If you are on a different Ubuntu release, verify package availability first or use the source-build method.

Update Ubuntu Packages

Open a terminal window before running the following commands.

sudo apt update

Applying outstanding upgrades (sudo apt upgrade) before installing Python prevents dependency conflicts, especially on servers that have not been updated recently.

Install Python 3.10 from Ubuntu Repositories

Ubuntu 22.04 LTS, elementary OS 7, Pop!_OS 22.04, and other distributions based on Ubuntu 22.04 LTS already include python3.10 in their main repositories. Install the interpreter, virtual environment module, and legacy Distutils support in a single command:

sudo apt install python3.10 python3.10-venv python3.10-distutils

Verify the interpreter matches the expected release:

python3.10 --version
Python 3.10.12

The exact patch version depends on your Ubuntu release and update level. Ubuntu 22.04 LTS typically reports 3.10.12 with Ubuntu security patches, while Deadsnakes (or a source build) may provide newer 3.10.x maintenance releases.

Run a quick smoke test to ensure core modules load correctly:

python3.10 -c "import ssl, sqlite3; print('Python 3.10 ready on Ubuntu')"

Install Python 3.10 via Deadsnakes PPA

Ubuntu 24.04 LTS ships Python 3.12 by default, so you typically rely on the community-maintained Deadsnakes PPA for python3.10 packages. Deadsnakes availability can change over time, so always verify the candidate version shown by APT before installing.

If add-apt-repository is missing on minimal servers or containers, install the helper package first:

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

Verify that APT recognizes the new repository before proceeding with installation:

apt-cache policy python3.10
python3.10:
  Installed: (none)
  Candidate: 3.10.19-1+noble1
  Version table:
      3.10.19-1+noble1 500
          500 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 Packages

The output confirms the Deadsnakes PPA is active and offering Python 3.10 packages. Now install the interpreter and essential modules:

sudo apt install python3.10 python3.10-venv python3.10-dev

Deadsnakes packages are community-maintained. Monitor security advisories and be prepared to pin or rebuild packages yourself if a critical CVE appears before patched binaries land in the PPA.

Once installation finishes, confirm the interpreter reports the installed version (patch releases vary between Ubuntu repositories and Deadsnakes PPA):

python3.10 --version

Optional Python 3.10 Modules for Debugging and Development

Install additional modules when your workflow demands debugging tools, GUI bindings, or compatibility layers:

python3.10-dbg provides debugging symbols for profiling, crash analysis, or gdb attachments.

sudo apt install python3.10-dbg

python3.10-dev adds headers and static libraries required to compile native extensions.

sudo apt install python3.10-dev

python3.10-venv enables the built-in venv module for per-project environments.

sudo apt install python3.10-venv

python3.10-distutils ships the legacy Distutils build system still used by older setup.py scripts.

sudo apt install python3.10-distutils

python3.10-lib2to3 installs modernization tools for porting Python 2 code to Python 3.

sudo apt install python3.10-lib2to3

python3.10-gdbm provides GNU dbm bindings for lightweight key-value storage.

sudo apt install python3.10-gdbm

python3.10-tk installs Tkinter for GUI applications.

sudo apt install python3.10-tk

Combine packages into one apt invocation to save time:

sudo apt install python3.10-venv python3.10-dev python3.10-gdbm python3.10-tk

Only install python3.10-distutils or python3.10-lib2to3 when older build scripts require them. Modern projects rely on pip, setuptools, wheel, or pyproject.toml-based tooling instead.

Compile Python 3.10 from Source on Ubuntu

Compile Python 3.10 manually when you need Link Time Optimization, custom prefixes, or independent upgrade cycles. Source builds install alongside Ubuntu’s system Python without overwriting /usr/bin/python3.

Download the Latest Python 3.10.x Source Tarball

Download the latest 3.10.x release directly from python.org using wget and extract the archive:

PYTHON_VERSION="3.10.19"
wget "https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz"
tar -xf "Python-${PYTHON_VERSION}.tar.xz"
cd "Python-${PYTHON_VERSION}"

Check the Python.org downloads page for the latest 3.10.x maintenance release. Replace 3.10.19 in the commands above with the newest patch version when available.

Install Build Dependencies

Before compiling, install the libraries required for SSL, compression, readline, Tk, and UUID support:

sudo apt install -y build-essential zlib1g-dev libgdbm-dev libnss3-dev \
libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev liblzma-dev uuid-dev \
tk-dev pkg-config

The ncurses development package name differs between Ubuntu 22.04 and 24.04:

Ubuntu 22.04 LTS:

sudo apt install -y libncurses5-dev

Ubuntu 24.04 LTS:

sudo apt install -y libncurses-dev

Most dependency package names are the same across both supported LTS releases, but always verify the install succeeds on your system before continuing. If any optional module fails to build, install the corresponding -dev package and rebuild.

Configure and Build Python 3.10

Compile Python with optimization flags. The following example installs Python under /usr/local/python3.10 to avoid overwriting your system interpreter:

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

Using make altinstall instead of make install keeps /usr/bin/python3 untouched while adding /usr/local/python3.10/bin/python3.10.

Register Libraries and Test the Build

After compilation completes, point the dynamic linker at your custom installation, reload the cache, and create a convenience symlink:

echo '/usr/local/python3.10/lib' | sudo tee /etc/ld.so.conf.d/python3.10.conf
sudo ldconfig
sudo ln -s /usr/local/python3.10/bin/python3.10 /usr/local/bin/python3.10

Verify the build and confirm critical modules compiled successfully:

python3.10 --version
python3.10 -c "import ssl, sqlite3, bz2; print('Source build is healthy')"

If the second command fails, reinstall the missing -dev packages, rerun ./configure, and rebuild the installation.

Create an Update Script for Source-Compiled Python 3.10

When you compile Python from source, security updates require manual recompilation. The following script automates the download, build, and installation process so you can keep your source-compiled Python 3.10 current with the latest maintenance releases.

Create a dedicated build directory and save the update script:

sudo mkdir -p /opt/python3.10-build
sudo nano /opt/python3.10-build/update-python3.10.sh

Add the following script content:

#!/usr/bin/env bash
set -euo pipefail

# Configuration
INSTALL_PREFIX="/usr/local/python3.10"
BUILD_DIR="/opt/python3.10-build"
LOG_FILE="${BUILD_DIR}/update.log"

if [ "${EUID:-0}" -ne 0 ]; then
    echo "Error: run this script as root (for example: sudo ${BUILD_DIR}/update-python3.10.sh)"
    exit 1
fi

# Check for required tools
for cmd in gcc make wget curl tar grep sort nproc; do
    if ! command -v "$cmd" >/dev/null 2>&1; then
        echo "Error: $cmd is required but not installed."
        echo "Install prerequisites first, then rerun this script."
        exit 1
    fi
done

mkdir -p "$BUILD_DIR"

# Get current installed version (if any)
CURRENT_VERSION="none"
if [ -x "${INSTALL_PREFIX}/bin/python3.10" ]; then
    CURRENT_VERSION=$("${INSTALL_PREFIX}/bin/python3.10" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || true)
    CURRENT_VERSION=${CURRENT_VERSION:-none}
fi

# Fetch latest Python 3.10.x version from python.org downloads page
LATEST_VERSION=$(curl -fsSL https://www.python.org/downloads/source/ | grep -oE 'Python-3\.10\.[0-9]+\.tar\.xz' | sort -V | tail -1 | grep -oE '3\.10\.[0-9]+')

if [ -z "${LATEST_VERSION:-}" ]; then
    echo "Error: could not detect the latest 3.10.x release from python.org"
    exit 1
fi

echo "Current version: ${CURRENT_VERSION}"
echo "Latest version:  ${LATEST_VERSION}"

if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
    echo "Already up to date."
    exit 0
fi

echo "Updating to ${LATEST_VERSION}..."
echo "$(date -Is): Starting update to ${LATEST_VERSION}" >> "$LOG_FILE"

cd "$BUILD_DIR"

# Clean previous builds in the dedicated build directory
rm -rf Python-3.10.*

# Download, extract, build
wget -q "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}"
./configure --enable-optimizations --with-ensurepip=install --prefix="$INSTALL_PREFIX"
make -j"$(nproc)"
make altinstall

# Verify
NEW_VERSION=$("${INSTALL_PREFIX}/bin/python3.10" --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
echo "$(date -Is): Updated to ${NEW_VERSION}" >> "$LOG_FILE"
echo "Successfully updated to ${NEW_VERSION}"

Make the script executable:

sudo chmod +x /opt/python3.10-build/update-python3.10.sh

Run the script manually when you want to check for updates:

sudo /opt/python3.10-build/update-python3.10.sh

Avoid automating this with cron. Compilation can fail due to missing dependencies, failed tests, or network issues. Always run the script manually so you can monitor the output and address problems before they affect your system.

Install Pip for Python 3.10

Pip usually installs with the interpreter, but verifying its presence ensures you can manage packages without touching Ubuntu’s system directories. For a comprehensive guide to pip installation and configuration, see our Python pip installation guide for Ubuntu.

Install Pip via APT

Install the system-wide pip package so Ubuntu manages updates automatically:

sudo apt install python3-pip

While this command wires pip to /usr/bin/python3, you can still bootstrap pip specifically for Python 3.10:

python3.10 -m ensurepip --upgrade
python3.10 -m pip --version

The ensurepip module installs pip in the Python 3.10 site-packages directory even when the system default interpreter differs.

Bootstrap Pip with get-pip.py

For air-gapped systems or custom builds, download the latest bootstrap script and execute it with Python 3.10:

wget https://bootstrap.pypa.io/get-pip.py
python3.10 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.10 -m pip

Always call pip through the desired interpreter to avoid cross-version confusion:

python3.10 -m pip install package_name
python3.10 -m pip install --upgrade package_name
python3.10 -m pip uninstall package_name

Replace package_name with libraries such as numpy, fastapi, or ansible-core. Using python3.10 -m pip keeps dependency management isolated from the system interpreter.

Ubuntu 23.04 and newer mark the system Python as “externally managed” (PEP 668). If you try to run python3.10 -m pip install <package> against the base interpreter on Ubuntu 24.04 or newer, pip prints an error unless you work inside a virtual environment or pass --break-system-packages. The latter flag bypasses Ubuntu’s protections but is risky; the recommended approach is to create a venv per project as shown in the virtual environments section below.

Work in Python 3.10 Virtual Environments

Virtual environments prevent package conflicts between projects by providing isolated site-packages directories.

Create a Python 3.10 Virtual Environment

First, create a dedicated directory for your environments (for example ~/venvs) and provision a new one with python3.10:

python3.10 -m venv ~/venvs/py310

Replace ~/venvs/py310 with any path meaningful to your workflow.

Activate the Virtual Environment

Next, activate the environment so your shell points python and pip to the local installation:

source ~/venvs/py310/bin/activate

The prompt changes to include the environment name, indicating successful activation. Install packages as needed while the environment remains active.

Deactivate the 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 when you need to change which interpreter launches when you type python. This approach keeps /usr/bin/python3 untouched, preserving system scripts that depend on Ubuntu’s default version.

Register only the interpreters already installed on your system. If /usr/bin/python is not available, install the python-is-python3 package first or skip update-alternatives entirely.

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 4
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 5

Once you have registered each interpreter, select the default:

sudo update-alternatives --config python

Only adjust /usr/bin/python (the legacy Python 2 shim). Leave /usr/bin/python3 at the system default to avoid breaking apt, cloud-init, or other distribution utilities.

Troubleshooting Common Python 3.10 Installation Issues

Missing Development Headers During Compilation

The configure script may report warnings about missing optional libraries when development headers are not installed. While Python will compile successfully, certain standard library modules like _ssl, _bz2, or _sqlite3 will be unavailable. Review the configure output carefully:

./configure --enable-optimizations --with-ensurepip=install --prefix=/usr/local/python3.10 2>&1 | grep "disabled"

This command displays all disabled modules. Additionally, after running make, check for “Failed to build these modules” messages near the end of the compilation output. Install the corresponding -dev packages, then run ./configure and make again to rebuild with full module support.

Shared Library Linking Errors

When running python3.10 after source compilation, you may encounter an error stating error while loading shared libraries: libpython3.10.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.

First, verify the library exists:

find /usr/local -name "libpython3.10.so*"

Then update the linker cache with the correct path. If you installed to the default prefix, use:

sudo ldconfig /usr/local/lib

Alternatively, add the library path to your environment permanently by creating a configuration file:

echo "/usr/local/python3.10/lib" | sudo tee /etc/ld.so.conf.d/python3.10.conf
sudo ldconfig

PIP Externally-Managed Environment Errors

If pip blocks a global install with an “externally-managed-environment” message (Ubuntu 23.04 and newer), switch to a virtual environment instead:

python3.10 -m venv myproject_env
source myproject_env/bin/activate
pip install package-name

Alternatively, use the --break-system-packages flag to bypass the restriction, though this approach risks dependency conflicts with apt packages and is not recommended for production systems:

python3.10 -m pip install --break-system-packages package-name

APT Breaking After Installing Python 3.10 PPA

If apt update or apt install fails with Python-related errors after adding the Deadsnakes PPA, ensure you did not accidentally replace Ubuntu’s system Python 3 interpreter. Check the /usr/bin/python3 symlink:

ls -la /usr/bin/python3

This should resolve to the Ubuntu default version (for example python3.12 on 24.04, python3.10 on 22.04), not an alternate version. If it is incorrect, reinstall the default Python package so dpkg restores the shipped files:

sudo apt install --reinstall python3-minimal

If you are running a minimal container where python3-minimal is not installed, install it first. Additionally, always invoke Python 3.10 explicitly using python3.10 rather than modifying the python3 symlink.

Virtual Environment Creation Fails

When python3.10 -m venv fails with “ensurepip is not available” or similar errors, the python3.10-venv package is missing. Install it explicitly:

sudo apt install python3.10-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.

Update or Remove Python 3.10

Keep Python 3.10 patched just like any other package. Use apt for repository builds and manual cleanup for source installations.

Update Python 3.10 Packages

sudo apt update
sudo apt install --only-upgrade python3.10 python3.10-venv python3.10-dev

This upgrades only the Python 3.10 packages you installed, without pulling in unrelated system upgrades. If you prefer to update everything at once, use sudo apt upgrade instead.

Remove Python 3.10

If a project no longer needs Python 3.10, remove only copies installed from the PPA or manual builds.

Do not purge python3.10 on Ubuntu 22.04 LTS or derivatives where it is the default system interpreter. Removing it breaks apt, cloud-init, and desktop utilities. The following commands are safe for Ubuntu 24.04 LTS and newer when Python 3.10 was added from the Deadsnakes PPA as an additional interpreter.

sudo apt remove --purge python3.10 python3.10-venv python3.10-dev
sudo apt autoremove --purge

Additionally, remove the Deadsnakes PPA if your system no longer requires Python 3.10 packages:

sudo add-apt-repository --remove ppa:deadsnakes/ppa -y
sudo apt update

Confirm the PPA no longer exists in your APT sources:

grep -R "deadsnakes" /etc/apt/sources.list.d/ || echo "No Deadsnakes entries found"

For source builds, delete the installation directory and ld.so entry. When you compiled with the default prefix (/usr/local), remove these files:

Warning: The following commands permanently delete your source-compiled Python 3.10 installation under /usr/local/python3.10, plus any third-party modules you installed into that prefix. Back up anything you need before continuing.

sudo rm -rf /usr/local/python3.10
sudo rm -f /usr/local/bin/python3.10
sudo rm /etc/ld.so.conf.d/python3.10.conf
sudo ldconfig

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

Warning: This permanently deletes the source-compiled Python 3.10 prefix. If you created a convenience symlink (for example /usr/local/bin/python3.10), remove it as well.

sudo rm -rf /opt/python3.10
sudo rm -f /usr/local/bin/python3.10
sudo ldconfig

Remove update-alternatives Entries

If you configured update-alternatives for Python version switching, remove the python3.10 entry:

sudo update-alternatives --remove python /usr/bin/python3.10

Verify the removal completed successfully:

sudo update-alternatives --list python

Conclusion

Python 3.10 delivers a mature interpreter with security coverage through October 2026, pattern matching syntax, and modernized type hints. The installation process covers Ubuntu 22.04 LTS repositories, Deadsnakes PPA integration, source compilation with custom prefixes, and virtual environment management. Your Ubuntu system now runs Python 3.10 alongside the default interpreter, enabling legacy compatibility, vendor-certified deployments, and controlled upgrades without breaking system utilities.

Leave a Comment