Ubuntu 24.04 ships with Python 3.12, but if you need the newest language features, performance improvements, and the free-threaded build of Python 3.13, you have to install it yourself. In this guide you will install Python 3.13 on Ubuntu from the trusted deadsnakes PPA, verify it, and set up an isolated virtualenv so every project gets its own clean set of packages. By the end, you will be able to spin up a fresh Python 3.13 environment in under a minute.
Prerequisites
- A machine running Ubuntu 24.04 (works on 22.04 too) — server or desktop.
- A non-root user with sudo privileges.
- An active internet connection.
- About 10 minutes of your time.
Step 1: Update your package lists and install prerequisites
Start by refreshing apt and installing the helper that lets you add PPAs (Personal Package Archives). The software-properties-common package provides the add-apt-repository command, which is missing on minimal server installs.
sudo apt update && sudo apt upgrade -y
sudo apt install -y software-properties-common
The first line pulls the latest package indexes and applies pending updates. The second installs the PPA helper so Step 2 does not fail with a "command not found" error.
Step 2: Add the deadsnakes PPA
Ubuntu's official repositories only carry one Python version per release, so we use the community-maintained deadsnakes PPA — the standard, widely documented source for newer Python builds on Ubuntu. It is maintained by the same team that packages Python for Debian.
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt update
The first command registers the PPA; the second refreshes the package index so apt can see the new Python 3.13 packages. If you are on a production server and dislike third-party repos, the alternative is compiling from source — but the PPA is what nearly every guide and CI image uses, and it receives security updates.
Step 3: Install Python 3.13
Install the interpreter, the venv module package, and the development headers (needed later if you install packages with C extensions like numpy or psycopg2).
sudo apt install -y python3.13 python3.13-venv python3.13-dev
This places the interpreter at /usr/bin/python3.13 alongside your system Python 3.12 — it does not replace it, which is exactly what you want, because Ubuntu's own tools depend on the system Python.
Step 4: Verify the installation
Confirm the new interpreter is on your PATH and check its exact version:
python3.13 --version
which python3.13
You should see output like Python 3.13.2 and /usr/bin/python3.13. Try the interactive shell once to be sure it starts cleanly:
python3.13 -c "import sys; print(sys.version)"
If this prints the version string with no errors, the interpreter is fully functional.
Step 5: Create a virtual environment
Never install project packages into the system Python — one project's dependencies will eventually break another's. A virtualenv gives each project its own isolated site-packages directory. Create one inside your project folder:
mkdir -p ~/projects/myapp && cd ~/projects/myapp
python3.13 -m venv venv
python3.13 -m venv venv creates a venv/ directory containing a private copy of the Python 3.13 interpreter, pip, and an empty package set. The python3.13-venv package from Step 3 makes sure the ensurepip bootstrap is available, so the environment comes with pip pre-installed.
Step 6: Activate the environment and install packages
Activate the environment, then upgrade its bundled pip before installing anything:
source venv/bin/activate
pip install --upgrade pip
pip install requests
Notice your shell prompt changes to show (venv) — that prefix means every python and pip command now points inside the environment. Installing requests touches only venv/lib/python3.13/site-packages; your system Python is untouched. Verify with a quick smoke test:
python -c "import requests; print('requests', requests.__version__, 'on', __import__('sys').version.split()[0])"
which python
The output should show the 3.13 version and a path inside ~/projects/myapp/venv.
Step 7: Freeze your dependencies and learn to recreate the environment
Good Python hygiene means your environment is reproducible. Record exact versions, then prove you can rebuild from scratch:
pip freeze > requirements.txt
cat requirements.txt
deactivate
rm -rf venv
python3.13 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
pip freeze pins every installed package. Deleting venv/ and rebuilding from requirements.txt is the standard workflow for onboarding teammates and for CI pipelines — the environment is disposable, the requirements file is the source of truth. Add venv/ to your .gitignore so you never commit it.
echo "venv/" >> .gitignore
Bonus: install standalone CLI tools with pipx (without polluting anything)
Sometimes you want a Python-based command-line tool — black, ruff, poetry, yt-dlp — available everywhere, but you do not want it tied to one project venv or to the system Python. pipx solves this: it installs each tool into its own isolated environment and symlinks just the executable onto your PATH.
sudo apt install -y pipx
pipx install --python /usr/bin/python3.13 black
pipx ensurepath
The --python flag pins the tool to your new interpreter, so black runs on Python 3.13 even though your login shell still uses the system Python elsewhere. pipx ensurepath adds ~/.local/bin to your PATH if it is not there already — log out and back in (or source ~/.bashrc) for it to take effect.
Verify the setup and see what is installed:
black --version
pipx list
Upgrading and removing tools is equally clean — pipx upgrade black and pipx uninstall black never touch your project environments. For tools you use daily across many projects, pipx is the correct layer; for project dependencies, stick with the per-project venv from Steps 5–6.
Verify it worked
Run this final checklist from a fresh terminal:
python3.13 --version # Python 3.13.x
cd ~/projects/myapp && source venv/bin/activate
python --version # still 3.13.x, now inside the env
pip list # shows requests and friends, nothing system-wide
deactivate # prompt prefix (venv) disappears
If all four behave as described, Python 3.13 is installed system-wide and your project has a healthy isolated environment. For a second project, just repeat Steps 5–6 in a new folder — each gets its own sandbox.
Common issues and fixes
1. sudo: add-apt-repository: command not found
Minimal Ubuntu Server images omit the PPA helper. Fix: sudo apt install -y software-properties-common, then repeat Step 2.
2. error: externally-managed-environment when running pip
Ubuntu 24.04 follows PEP 668 and blocks pip installs outside a virtualenv to protect system packages. This is expected — do not bypass it with --break-system-packages on a shared system. Create and activate a venv (Steps 5–6) and install there instead.
3. ensurepip is not available when creating the venv
You installed the interpreter but not the venv support package. Fix: sudo apt install -y python3.13-venv, then create the environment again.
4. python3.13: command not found right after installing
Your shell has a stale command hash. Run hash -r or open a new terminal. If it still fails, verify the binary exists: ls /usr/bin/python3.13. On Ubuntu versions older than 22.04 the deadsnakes PPA may not publish 3.13 builds — upgrade the OS or compile from source.
5. bash: venv/bin/activate: No such file or directory
You are in the wrong directory, or the environment was created with a different name. Run ls to confirm venv/ exists in your current folder, or recreate it with python3.13 -m venv venv.
6. Builds fail with Python.h: No such file or directory when installing packages
Some packages compile C extensions and need the headers from Step 3. Fix: sudo apt install -y python3.13-dev build-essential, then reinstall the package.
You now have Python 3.13 installed safely alongside Ubuntu's system Python, plus a repeatable virtualenv workflow you can use for every project. If you would rather have an expert handle your server setup — Python environments, web stacks, databases, or full VPS hardening — XpertBees does exactly that for businesses every day.

