Ctrl K

Multiple Python Versions on Ubuntu

Install several Python versions side by side on Ubuntu using the deadsnakes PPA, then create a venv pinned to a specific version.

Ubuntu ships with one Python version per release. The deadsnakes PPA provides additional Python versions as separate packages so multiple versions can coexist. Each version installs as its own binary (python3.9, python3.10, etc.) and can be used to create version pinned virtual environments.

Add the deadsnakes PPA

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

Install Python versions

Install only the versions actually needed. Each one installs alongside the system Python without replacing it.

sudo apt install python3.9 python3.10 python3.11 python3.12 python3.13

Verify the installed binaries:

ls /usr/bin/python3*

Install venv support

On Ubuntu, the venv module ships in a separate package per version. Install the matching venv package for each Python version that needs to create virtual environments.

sudo apt install python3.9-venv python3.10-venv python3.11-venv python3.12-venv

Create a venv with a specific version

Call the version specific binary to create the venv. The resulting environment is pinned to that interpreter.

python3.11 -m venv myenv
source myenv/bin/activate
python --version
pip install --upgrade pip