How to Install Python on Ubuntu 24.04

By 

Updated on

9 min read

Install Python on Ubuntu 24.04

When you start a Python project on Ubuntu 24.04, the first question is usually whether the system Python is enough or whether you need a newer interpreter. Ubuntu already includes Python 3.12, but you may still need to install pip, the venv module, or a separate Python version such as 3.13 or 3.14.

This guide explains how to install Python on Ubuntu 24.04 using the default Ubuntu packages, the deadsnakes PPA, and a source build. It also shows how to create a virtual environment so project packages do not affect the system Python.

Ubuntu 24.04 Default Python Version

Ubuntu 24.04 ships with Python 3.12 as the default Python 3 interpreter. To check the version on your system, run:

Terminal
python3 --version
output
Python 3.12.3

The exact patch version may change as Ubuntu publishes security updates, but the default interpreter remains Python 3.12. For most system scripts and many development tasks, this version is enough.

Do not replace the /usr/bin/python3 interpreter. Ubuntu tools such as apt, system maintenance scripts, and desktop utilities expect the distribution-provided Python version. If you need a newer Python release, install it alongside the default interpreter and call it by its versioned command, such as python3.13 or python3.14.

Quick Reference

TaskCommand
Check Ubuntu’s default Python versionpython3 --version
Install the default Python, pip, and venvsudo apt install python3 python3-pip python3-venv
Add a plain python commandsudo apt install python-is-python3
Create a virtual environment with the default Pythonpython3 -m venv myproject
Add deadsnakes PPAsudo add-apt-repository ppa:deadsnakes/ppa
Install Python 3.13 from PPAsudo apt install python3.13
Install Python 3.14 from PPAsudo apt install python3.14
Install venv modulesudo apt install python3.13-venv
Create a virtual environmentpython3.13 -m venv myproject
Activate virtual environmentsource myproject/bin/activate
Deactivate virtual environmentdeactivate
Build from source./configure --enable-optimizations && make -j $(nproc)
Install source build safelysudo make altinstall

Installing the Default Python Packages

If you only need the Python version that comes with Ubuntu 24.04, install the standard Python tooling from the Ubuntu repositories. This gives you pip3 and the venv module for creating isolated project environments.

First, update the package index:

Terminal
sudo apt update

Install Python, pip, and the virtual environment module:

Terminal
sudo apt install python3 python3-pip python3-venv

The command is safe to run when Python 3 is already installed. Apt keeps the existing interpreter and installs any missing packages.

Verify the installed commands:

Terminal
python3 --version
pip3 --version

On Ubuntu 24.04, python3 points to Python 3.12. The pip3 command installs packages for the system Python environment, but Ubuntu protects system-managed Python packages from accidental changes. For project dependencies, use a virtual environment instead of installing packages globally with pip3.

Ubuntu 24.04 provides no unversioned python command. Scripts and build tools that call python directly fail until you install python-is-python3, which symlinks /usr/bin/python to the default Python 3 interpreter. That package changes only the command name, not which version runs.

Create a virtual environment with the default Python:

Terminal
python3 -m venv myproject

Activate it:

Terminal
source myproject/bin/activate

Inside the environment, python and pip point to the isolated project environment:

Terminal
python --version
python -m pip --version

When you are done working in the project, deactivate the environment:

Terminal
deactivate

Installing Python from the Deadsnakes PPA

The third-party deadsnakes PPA provides newer Python versions packaged for Ubuntu. Use this method when you need Python 3.13, Python 3.14, or another supported version alongside Ubuntu’s default Python 3.12.

Warning
The deadsnakes PPA is not an official Ubuntu repository, and its maintainers do not guarantee timely security updates. Prefer Ubuntu packages for production or security-critical systems unless you specifically need another Python version.

The PPA does not replace the system Python. It installs versioned commands such as python3.13 and python3.14, which is the safer approach on Ubuntu.

  1. Install the prerequisites and add the PPA:

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

    Press Enter when prompted to confirm.

  2. Install Python 3.13:

    Terminal
    sudo apt update
    sudo apt install python3.13

    To install Python 3.14 instead, replace python3.13 with python3.14:

    Terminal
    sudo apt install python3.14
  3. Verify the installation:

    Terminal
    python3.13 --version

    The command prints the installed Python 3.13 patch release. You can also confirm the binary location:

    Terminal
    which python3.13
  4. Install the venv module for the same interpreter:

    Terminal
    sudo apt install python3.13-venv

    If you installed Python 3.14, use:

    Terminal
    sudo apt install python3.14-venv
  5. Create a virtual environment and use pip inside it:

    Terminal
    python3.13 -m venv myproject
    source myproject/bin/activate
    python -m pip install --upgrade pip
Info
The system default python3 still points to Python 3.12. To use the newly installed version, run python3.13 or python3.14 explicitly.

Updating Python on Ubuntu 24.04

Running sudo apt upgrade does not move Ubuntu to a newer Python minor version. Ubuntu 24.04 stays on the Python 3.12 series for the life of the release, and apt delivers only 3.12.x security and bug-fix updates within it:

Terminal
sudo apt update && sudo apt upgrade

When a project needs Python 3.13 or 3.14, you are not updating the system interpreter; you are installing a second one next to it. Use the deadsnakes PPA for a packaged build, or build from source when you need a specific upstream patch release. Both leave /usr/bin/python3 on Python 3.12, which is what keeps apt and the desktop tools working.

Pin the version per project rather than system-wide. Create the virtual environment with the interpreter you want, and every command inside it uses that version.

Installing Python from Source

Compiling Python from source allows you to install any version and customize the build options. However, you will not be able to manage the installation through the apt package manager.

The following steps show how to compile Python 3.14.7. If you are installing a different version, replace the version number in the commands below.

  1. Install the libraries and dependencies required to build Python:

    Terminal
    sudo apt update
    sudo apt install build-essential zlib1g-dev libncurses-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev liblzma-dev
  2. Download the source code from the Python download page using wget :

    Terminal
    wget https://www.python.org/ftp/python/3.14.7/Python-3.14.7.tgz
  3. Extract the archive :

    Terminal
    tar -xf Python-3.14.7.tgz
  4. Navigate to the source directory and run the configure script:

    Terminal
    cd Python-3.14.7
    ./configure --enable-optimizations

    The --enable-optimizations flag runs profile-guided optimization tests, which makes the build slower but produces a faster Python binary.

  5. Start the build process:

    Terminal
    make -j $(nproc)

    The -j $(nproc) option uses all available CPU cores for a faster build.

  6. Install the Python binaries using altinstall. With the default /usr/local prefix, make install can create /usr/local/bin/python3, which may shadow Ubuntu’s /usr/bin/python3 in the shell’s PATH. Use altinstall to avoid changing which interpreter runs as python3:

    Terminal
    sudo make altinstall
  7. Verify the installation:

    Terminal
    python3.14 --version
    output
    Python 3.14.7

Setting Up a Virtual Environment

After installing a new Python version, create a virtual environment for your project to keep dependencies isolated:

Terminal
python3.13 -m venv myproject

Activate the virtual environment:

Terminal
source myproject/bin/activate

Your shell prompt will change to show the environment name. Inside the virtual environment, python and pip point to the version you used to create it.

For a source-built Python 3.14 installation, use the versioned command:

Terminal
python3.14 -m venv myproject

To deactivate the virtual environment:

Terminal
deactivate

For more details, see our guide on how to create Python virtual environments .

Optional: Uninstalling the PPA Version

To remove the PPA version:

Terminal
sudo apt remove python3.13 python3.13-venv

To remove the PPA itself:

Terminal
sudo add-apt-repository --remove ppa:deadsnakes/ppa

Troubleshooting

python3 already exists after installation
This is expected. Ubuntu 24.04 includes Python 3.12 by default, so installing the default packages may only add missing tools such as pip3 or venv.

pip reports an externally managed environment
Ubuntu protects system-managed Python packages. Create a virtual environment with python3 -m venv myproject, activate it, and install packages with python -m pip install package-name inside the environment.

No module named venv
Install the matching venv package. For Ubuntu’s default Python, run sudo apt install python3-venv. For Python 3.13 from the PPA, run sudo apt install python3.13-venv.

E: Unable to locate package python
Ubuntu 24.04 does not ship a package named python. Python 2 was removed from the archive, and the interpreter is packaged as python3. Run sudo apt install python3 instead. If a script or build tool calls a plain python command, install python-is-python3.

Unable to locate package python3.13 or python3.14
Run sudo apt update after adding the deadsnakes PPA. If the package is still unavailable, check that the PPA supports your Ubuntu release and CPU architecture.

python3 still shows Python 3.12
The python3 command should continue to use Ubuntu’s default interpreter. Run the newer version with its versioned command, such as python3.13 or python3.14.

FAQ

Should I use the PPA or build from source?
Use the Ubuntu packages if Python 3.12 is enough. Use the deadsnakes PPA when you need a newer packaged interpreter such as Python 3.13 or 3.14. Build from source only if you need a specific upstream patch release or a custom build configuration.

Will installing a new Python version break my system?
No. Both methods install the new version alongside the system Python 3.12. The system python3 command is not affected. You access the new version with python3.13 or python3.14.

How do I make the new Python version the default?
You can use update-alternatives to configure it, but this is not recommended. Many Ubuntu system tools depend on the default python3 being the version that shipped with the OS. Use virtual environments instead.

How do I install pip for the new Python version?
The recommended approach is to use a virtual environment. Install python3.13-venv, create a venv, activate it, and use python -m pip inside the environment.

What is the difference between install and altinstall when building from source?
altinstall installs a versioned binary such as python3.14 without creating an unversioned python3 command. With the default prefix, install may create /usr/local/bin/python3, which can shadow Ubuntu’s /usr/bin/python3 command in the shell’s PATH.

Does Ubuntu 24.04 include pip by default?
Ubuntu 24.04 includes Python 3.12 but does not include pip in the base installation. Install it with sudo apt install python3-pip. For newer Python versions, use python3.13 -m pip inside a virtual environment.

Conclusion

Stick with Ubuntu’s Python 3.12 plus python3-pip and python3-venv for most projects. Reach for the deadsnakes PPA when a project pins to 3.13 or 3.14, and build from source only for a specific upstream patch.

For more on Python package management, see our guide on how to use pip .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page