Install Python on Ubuntu 26.04 or 24.04 with APT, or use a separate interpreter when a project needs another version. Python is a programming language used for scripts, applications and automation.
This guide covers installation, virtual environments, pip, alternative versions, updates and troubleshooting. If something does not work, leave a comment or contact us.
1. Check Ubuntu and Python
Open a terminal and check the Ubuntu release, Python version and the executable selected by your shell:
A typical Ubuntu 24.04 installation uses Python 3.12 and 26.04 uses 3.14. Patch numbers can differ. If the first Python command fails or selects a different path, the final command checks Ubuntu’s interpreter directly. A virtual environment or version manager may change what your shell finds first.
2. Install Python using APT
Ubuntu’s repository is the simplest choice for most users. Refresh the package list and install the interpreter plus virtual-environment support:
APT reports when the packages are already installed. It updates these packages through Ubuntu’s repositories; it does not promise the newest Python release from python.org. Check the interpreter and run a small example:
The second line should print Hello from Python!. To run a saved file later, use python3 filename.py. On Ubuntu, python may not exist outside a virtual environment; use python3 or an explicit interpreter path.
3. Create a project and install a package
A virtual environment keeps a project’s Python packages separate from Ubuntu and other projects. Create a new practice directory. If it already exists, choose a different name rather than using an existing project:
The prompt normally starts with (.venv); pip should report a path inside the project. If a step fails, stop and fix it before continuing. The environment uses the interpreter selected when it was created.
Install a small example library into the activated environment and test it:
The command prints the installed Requests version. Use python -m pip so pip belongs to the selected interpreter. Install only packages you trust. To leave the environment, run deactivate; to return later, enter the project directory and run source .venv/bin/activate again.
If pip reports externally-managed-environment, create and activate a virtual environment instead of changing Ubuntu’s system packages. Avoid sudo pip and --break-system-packages on a normal host. For standalone Python command-line tools, consider pipx.
4. Choose another Python version
A project may require a newer or older minor version than Ubuntu provides. Check the project’s documented version and dependency support first. A newer Python release can require updates to libraries or native extensions.
uv manages separate user-owned interpreters and is a useful choice for development. A community PPA uses APT but adds a third-party repository and its maintenance policy. A source build offers build control but you must rebuild for security updates. None of these methods should replace /usr/bin/python3.
5. Install another version with uv
The official uv documentation offers a standalone installer. This downloads and runs third-party code as your user and may change shell startup files. Inspect the installer before running it:
Install curl with sudo apt install curl if needed. Quit less with q, then run the second block only if you trust the script, in the same terminal. Open a new terminal after installation if uv is not found. Select a version supported by your project; this example uses Python 3.15:
uv obtains managed CPython builds from python-build-standalone, not Ubuntu’s package archive. Availability depends on version and CPU architecture. Create a separate environment in a new directory:
Use a new directory if the example name exists. Check the printed version before installing project dependencies. To update uv when installed with its standalone installer use uv self update; check uv’s Python guide for managed interpreter updates and recreate project environments after changing interpreter versions.
6. Optional: Use a community PPA
The Deadsnakes PPA supplies some additional Python versions. It is community maintained, not an official Ubuntu repository, and does not guarantee timely security updates. Check the PPA page for your release, architecture and desired version before adding it. Do not use a repository for a different Ubuntu release.
If the required version is listed, add the repository and inspect the candidate. This example requests Python 3.11; replace the version only after checking availability:
Proceed only if both packages have suitable candidates for your Ubuntu release and architecture. Review the repository and installation transaction:
Use /usr/bin/python3.11 -m venv .venv in a new project directory to select that interpreter. Keep Ubuntu’s default /usr/bin/python3 unchanged. APT updates PPA packages while the repository remains enabled, subject to its maintainer publishing updates.
7. Optional: Build Python from source
Use this method when you need custom build settings. It takes more time and disk space, and APT will not update the result. This example installs Python 3.15.2 into its own prefix. Check the current source releases and the matching release checksum before choosing another version.
Create a fresh build directory and download the source. The checksum below is specific to the 3.15.2 XZ archive and should match the official release page. Stop if the check fails; a checksum checks the file against that published value, and signed verification provides a stronger independent authenticity check.
Continue only if the output says OK. If the build directory exists, choose another name and enter it. Check that /usr/local/python-3.15.2 does not exist before continuing. The install step needs sudo:
Stop if any command fails. Do not run the remaining steps if the prefix check fails. The private prefix and altinstall leave Ubuntu’s system interpreter in place. Verify the result and important optional modules:
A missing module usually means its development headers were absent at configure time. Install the appropriate headers and rebuild. To update a source build, verify the new release and build it into a new, version-specific prefix; migrate and test projects before removing the old one.
8. Update and remove Python safely
For Ubuntu and enabled PPA packages, refresh package information with sudo apt update and use sudo apt upgrade after reviewing the proposed system-wide upgrades. For a project, activate its environment before updating a dependency with python -m pip install --upgrade PACKAGE. Review compatibility and test the project first.
To remove a uv-managed interpreter, first list and inspect installations with uv python list --only-installed, then use uv python uninstall 3.15 only when no project needs it. Existing environments may stop working and need recreation. Consult uv’s command reference for exact matches.
To remove the PPA example, review sudo apt remove python3.11 python3.11-venv and the packages APT proposes to remove before accepting. Disable the PPA only after checking whether other installed packages depend on it. For a source install, back up anything needed and inspect its exact private prefix before removing it. Do not remove Ubuntu’s python3 package or delete shared system directories.
Troubleshooting
Frequently Asked Questions
Related guides: Visual Studio Code on Ubuntu | Install curl on Ubuntu | Install Node.js on Ubuntu.
