Multiple Python Versions on Ubuntu
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
Section titled “Add the deadsnakes PPA”sudo apt install software-properties-commonsudo add-apt-repository ppa:deadsnakes/ppasudo apt updateInstall Python versions
Section titled “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.13Verify the installed binaries:
ls /usr/bin/python3*Install venv support
Section titled “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-venvCreate a venv with a specific version
Section titled “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 myenvsource myenv/bin/activatepython --versionpip install --upgrade pip