How to Install Python on Linux (Ubuntu, Debian, Fedora) – 2026
Introduction
Python continues to be one of the most popular programming languages in 2026, and Linux remains the preferred operating system for many developers, data scientists, and system administrators. Whether you are setting up a development environment, deploying applications, or learning to code, understanding how to properly install Python on your Linux distribution is essential. This comprehensive guide covers the installation procedures for Ubuntu 26.04, Debian, and Fedora, as well as advanced topics like version management, virtual environments, and handling legacy Python versions.
By 2026, the Python ecosystem has matured significantly. Python 3.14 is the latest stable release, with Python 3.13 and 3.12 still receiving widespread support. Most Linux distributions now ship with Python 3 pre-installed, but understanding how to manage multiple versions, install additional interpreters, and set up isolated development environments is crucial for modern Python development. This guide will walk you through everything you need to know about installing Python on Linux in 2026 .
Table of Contents
- Understanding Python Versions in 2026
- Prerequisites for Python Installation
- Installing Python on Ubuntu 26.04
- Installing Python on Debian
- Installing Python on Fedora
- Installing pip on Linux Systems
- Managing Multiple Python Versions with pyenv
- Setting Up Virtual Environments
- Installing Python 2 for Legacy Applications (Ubuntu 26.04)
- Troubleshooting Common Installation Issues
- Best Practices for Python Development in 2026
- Conclusion
Understanding Python Versions in 2026
Before diving into installation procedures, it is important to understand the current Python version landscape. As of 2026, Python 3.14 is the latest major release, with Python 3.13 and 3.12 still being actively maintained. Python 3.8 reached its end-of-life in late 2024, though some enterprise distributions may still provide security backports .
Fedora 43 uses Python 3.14 as its system Python, while Ubuntu 26.04 ships with Python 3.13 as the default. Understanding these version differences is essential when choosing which Python interpreter to install for your specific use case. The table below summarizes the Python versions commonly available on major Linux distributions in 2026:
| Distribution | Default Python Version | Available Versions in Repositories |
|---|---|---|
| Ubuntu 26.04 | Python 3.13 | 3.13, 3.12, 3.11, 3.10, 3.9 |
| Debian 13 | Python 3.13 | 3.13, 3.12, 3.11 |
| Fedora 43 | Python 3.14 | 3.14, 3.13, 3.12, 3.11, 3.10, 3.9 |
Prerequisites for Python Installation
Before installing Python on any Linux distribution, you should ensure your system is up to date and has the necessary build tools. While the default Python version may already be installed, you will often need development headers and additional tools for compiling Python extensions.
For Ubuntu and Debian systems, you should install the following build dependencies:
sudo apt update
sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python3-openssl gitFor Fedora systems, the equivalent dependencies are:
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y openssl-devel bzip2-devel libffi-devel \
readline-devel sqlite-devel tk-devel gdbm-devel xz-develThese packages are essential whether you are installing Python from the distribution repositories or compiling from source. They ensure that Python can be built with all standard modules enabled .
Installing Python on Ubuntu 26.04
Ubuntu 26.04, codenamed “Resolute Raccoon,” ships with Python 3.13 as the default Python version. This version is fully supported and receives security updates through the official Ubuntu repositories. The installation process is straightforward and recommended for most users who do not need specific Python versions.
Installing the Default Python Version
To install the default Python 3 version on Ubuntu 26.04, use the following commands:
sudo apt update
sudo apt install python3 python3-dev python3-venvThe python3-dev package includes header files and static libraries needed for building Python extensions, while python3-venv provides the standard library module for creating virtual environments. After installation, verify that Python is correctly installed:
python3 --versionThis should output something similar to Python 3.13.2. You may also want to check that pip is available:
pip3 --versionIf the pip command is not found, you can install it separately:
sudo apt install python3-pipInstalling Alternative Python Versions on Ubuntu
Sometimes you need a specific Python version that is not the system default. Ubuntu 26.04 maintains packages for several Python versions in its official repositories. You can install Python 3.12, 3.11, 3.10, or 3.9 using the same pattern .
To install Python 3.12, for example:
sudo apt install python3.12 python3.12-dev python3.12-venvEach version installs with its own binary name, allowing multiple versions to coexist. You can invoke a specific version using:
python3.12 --versionIf you need Python versions not available in the official repositories, such as older versions or release candidates, you can use the deadsnakes PPA, though by 2026 this has largely been superseded by pyenv for most use cases.
Understanding Ubuntu’s Externally Managed Environment
A crucial change in recent Ubuntu versions is the implementation of PEP 668, which marks the system Python installation as externally managed. This means you cannot install packages system-wide using pip without special flags. When you attempt to run pip install outside a virtual environment, you will see an error message like this :
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.This is not a bug but a deliberate design choice to protect the system Python from accidental breakage. The recommended solution is to always use virtual environments for project-specific dependencies. If you need to install a package globally for your user only, you can use the --user flag:
pip3 install --user package-nameFor development environments where you understand the risks, you can override this behavior with the --break-system-packages flag, but this is strongly discouraged.
Installing Python on Debian
Debian, being the foundation for Ubuntu, follows similar patterns but with a stronger emphasis on stability. Debian 13 (currently in development) and Debian 12 include Python 3.11 or 3.12 as default. The installation procedure mirrors Ubuntu closely.
Basic Python Installation on Debian
First, update your package index and install Python:
sudo apt update
sudo apt install python3 python3-dev python3-venv python3-pipDebian also maintains multiple Python versions in its repositories. To see which versions are available:
apt search '^python3\.[0-9]+$'To install a specific version, such as Python 3.11:
sudo apt install python3.11 python3.11-dev python3.11-venvDebian-Specific Considerations
Debian is known for its conservative approach to package versions. The Python packages in Debian stable repositories may be older than the latest upstream releases. If you need a newer Python version, you have several options:
First, you can use the Debian backports repository, which provides newer versions of some packages for stable releases. Second, you can use pyenv, which is covered later in this guide. Third, for some use cases, you might consider using Debian Testing or Unstable branches, though these are not recommended for production systems.
Debian also implements the same externally-managed-environment protection as Ubuntu, so the same recommendations about using virtual environments apply .
Installing Python on Fedora
Fedora has historically been at the forefront of adopting new Python versions. Fedora 43, released in late 2025, uses Python 3.14 as its system Python. Fedora maintains an impressive collection of Python versions in its repositories, making it an excellent choice for Python developers who need to test across multiple interpreters .
Installing Python on Fedora 43
To install the default Python 3 version on Fedora:
sudo dnf install python3 python3-devel python3-pipThe python3-devel package provides the development headers, similar to python3-dev on Debian-based systems.
Installing Multiple Python Versions on Fedora
One of Fedora’s strengths is the availability of many Python versions in the official repositories. As of Fedora 43, you can install Python 3.14 (system default), 3.13, 3.12, 3.11, 3.10, 3.9, and even 3.6. Fedora also provides PyPy implementations for those interested in alternative Python runtimes .
To install a specific CPython version:
sudo dnf install python3.13 python3.13-devel
sudo dnf install python3.12 python3.12-devel
sudo dnf install python3.11 python3.11-develFor PyPy support:
sudo dnf install pypy pypy3.11After installation, each version is accessible using its specific binary name:
python3.14 --version
python3.13 --version
python3.12 --versionThis makes Fedora particularly useful for CI/CD environments and testing matrices where you need to validate code against multiple Python versions quickly.
Fedora’s Python Packaging Philosophy
Fedora’s approach to Python packaging differs from Debian’s in several important ways. While Fedora also protects the system Python from accidental modification, the implementation is less restrictive. You can still install packages system-wide using pip, though it is still recommended to use virtual environments for project isolation.
Fedora packages many popular Python libraries as RPMs, allowing you to install them using dnf. For example:
sudo dnf install python3-requests python3-numpy python3-pandasThis can be convenient for system-wide tools, but for development work, virtual environments remain the best practice.
Installing pip on Linux Systems
pip is the standard package installer for Python, and its installation varies slightly across distributions. In 2026, pip is typically included with Python installations, but sometimes it must be installed separately .
Installing pip on Ubuntu and Debian
On Ubuntu 26.04 and Debian, pip is available as a separate package:
sudo apt install python3-pipAfter installation, note that the command is pip3 rather than pip. If you want to use pip as the command, you can create an alias or install the python-is-python3 package:
sudo apt install python-is-python3This package symlinks python to python3 and pip to pip3. Alternatively, you can use the --user flag to install pip for your user only:
python3 -m pip install --user --upgrade pipInstalling pip on Fedora
On Fedora, pip is available through the official repositories:
sudo dnf install python3-pipFedora typically makes both pip3 and pip available after installation, with pip pointing to the Python 3 version by default.
Upgrading pip
Regardless of your distribution, you should consider upgrading pip to the latest version, especially if you are using an older distribution release:
pip3 install --upgrade pipFor user-only installation (recommended on Debian/Ubuntu):
pip3 install --user --upgrade pipManaging Multiple Python Versions with pyenv
While using distribution packages works well for many use cases, developers often need to manage multiple Python versions that may not be available in official repositories. This is particularly important for testing legacy codebases or working with pre-release versions. pyenv is the standard tool for this purpose in 2026 .
What is pyenv?
pyenv is a simple, unobtrusive tool that lets you easily switch between multiple versions of Python. It works by intercepting Python commands using shim scripts, allowing you to change the active Python version on a per-user, per-project, or per-shell basis. Unlike distribution packages, pyenv can install any Python version from 2.7.18 through the latest 3.14 release .
Installing pyenv
The recommended way to install pyenv is using the automatic installer:
curl https://pyenv.run | bashThis script clones pyenv and its plugins to ~/.pyenv and provides instructions for adding pyenv to your shell configuration. After running the installer, you need to add the following lines to your ~/.bashrc (for Bash users):
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init - bash)"For Zsh users, add similar lines to ~/.zshrc. After updating your shell configuration, restart your shell or run:
exec "$SHELL"Installing Python Versions with pyenv
Before installing Python versions with pyenv, you need the build dependencies. For Ubuntu/Debian, these were covered in the prerequisites section. For Fedora, the development group and specific libraries are needed.
To see all available Python versions:
pyenv install --listTo install a specific Python version, such as Python 3.12:
pyenv install 3.12pyenv automatically downloads the source code, compiles it with appropriate optimizations, and installs it to ~/.pyenv/versions/3.12.9. The compilation process takes several minutes but only needs to be done once per version.
For Python 2.7.18, which may be needed for legacy applications, the installation requires a special compiler flag due to C23 compatibility issues on modern systems:
CFLAGS="-std=c11" pyenv install 2.7.18This issue is specific to Python 2.7.18 and systems using GCC 14 or newer that default to the C23 standard .
Switching Between Python Versions
pyenv provides three levels of version selection:
- Global: Sets the default Python version for your user account
pyenv global 3.12- Local: Sets a Python version for a specific project directory
cd my-project
pyenv local 3.11This creates a .python-version file in the directory.
- Shell: Sets a Python version for the current shell session only
pyenv shell 3.13To verify which version is active:
python --versionUninstalling Python Versions
To remove a Python version managed by pyenv:
pyenv uninstall 3.12.9You can also revert to the system Python:
pyenv global systemSetting Up Virtual Environments
Virtual environments are isolated Python installations that allow you to manage project-specific dependencies without conflicts. In 2026, the standard library venv module is the recommended tool for creating virtual environments on all Linux distributions .
Why Use Virtual Environments?
The externally-managed-environment protection on modern Ubuntu and Debian systems makes virtual environments practically mandatory for Python development. Even on Fedora, where system-wide pip installs are allowed, virtual environments provide crucial benefits:
- Isolate dependencies between different projects
- Avoid version conflicts
- Allow testing with different package versions
- Keep the system Python clean and stable
- Reproducible environments for deployment
Creating Virtual Environments with venv
To create a virtual environment, navigate to your project directory and run:
cd ~/my-python-project
python3 -m venv .venvThe .venv directory (the name is conventional but arbitrary) contains a complete Python installation with its own site-packages directory. To activate the virtual environment:
source .venv/bin/activateWhen activated, your shell prompt changes to show the environment name, and python and pip commands point to the virtual environment’s binaries. To verify:
which python
# Should show something like /home/user/my-python-project/.venv/bin/pythonWith the virtual environment activated, you can install packages normally using pip:
pip install requests numpy pandasTo deactivate the virtual environment:
deactivateUsing pip with Virtual Environments
Inside an activated virtual environment, pip works without restrictions. You can create a requirements.txt file to document your dependencies:
pip freeze > requirements.txtTo recreate the environment on another system or after cleaning:
pip install -r requirements.txtVirtual Environments on High-Performance Computing Systems
For users working on shared systems like university clusters or HPC environments, virtual environments are particularly important. These systems often have module systems for loading software, and virtual environments integrate well with them .
The CHPC at the University of Utah recommends creating modules for virtual environments, allowing easy loading and unloading:
module load python3
python -m venv ~/my-python-venvs/my-environmentYou can then create a module file that sets the appropriate environment variables, making your custom environment as easy to load as any system software.
Installing Python 2 for Legacy Applications (Ubuntu 26.04)
Python 2 reached its end-of-life on January 1, 2020, and Ubuntu 26.04 has completely removed Python 2 from its official repositories. However, some organizations still maintain legacy applications that require Python 2.7. This section explains how to install Python 2.7 on Ubuntu 26.04 for those who have no other option .
Security Warning
Before proceeding, it is crucial to understand that Python 2 has not received security patches since 2020. Installing Python 2 on a modern system exposes you to known vulnerabilities. If you must run Python 2 applications, follow these precautions:
- Isolate Python 2 environments using containers or dedicated virtual machines
- Never expose Python 2 applications to the internet
- Run legacy scripts only in isolated, internal environments
- Plan for migration away from Python 2 as soon as possible
Installing Python 2.7.18 with pyenv
The recommended method for installing Python 2 on Ubuntu 26.04 is using pyenv, as it handles the compilation issues that arise with modern compilers. First, ensure you have the build dependencies installed (covered in the prerequisites section), then install Python 2.7.18 with the C11 compiler flag:
CFLAGS="-std=c11" pyenv install 2.7.18The C11 flag is necessary because Ubuntu 26.04’s GCC compiler defaults to the C23 standard, which treats false, true, and bool as keywords. Python 2.7.18’s codebase uses these as type definitions, causing compilation errors without this flag .
After installation, you can create a virtual environment using Python 2.7:
pyenv local 2.7.18
python -m virtualenv venv # Note: venv is not available in Python 2, need virtualenv packageInstalling pip for Python 2
pip for Python 2 must be installed using the legacy bootstrap script:
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python2 get-pip.py --userThis installs pip 20.3.4, the last version to support Python 2. Note that many Python packages have dropped Python 2 support, so you may need to specify older versions of dependencies.
Troubleshooting Common Installation Issues
Compilation Failures with pyenv
When installing Python versions with pyenv, compilation failures are the most common issue. These typically occur due to missing dependencies. On Ubuntu/Debian, ensure you have installed all build dependencies listed in the prerequisites section. On Fedora, verify that the development group and all necessary -devel packages are installed.
For Python 2.7.18 specifically, you may encounter the C23 compilation error discussed earlier. The solution is to set the CFLAGS environment variable:
CFLAGS="-std=c11" pyenv install 2.7.18pip Externally-Managed-Environment Error
On Ubuntu 26.04 and Debian, attempting to install packages system-wide with pip produces an error. This is expected behavior. The solution is to either use a virtual environment or install with the --user flag:
pip3 install --user package-nameCommand Not Found: pip
If pip is not found after installing python3-pip, you may need to use the pip3 command explicitly. Alternatively, add ~/.local/bin to your PATH if you installed pip with --user:
export PATH="$HOME/.local/bin:$PATH"SSL Module Missing
If Python compiles but lacks SSL support, verify that libssl-dev (Ubuntu/Debian) or openssl-devel (Fedora) is installed. After installing the missing package, you may need to reinstall Python:
pyenv uninstall 3.12
pyenv install 3.12Best Practices for Python Development in 2026
Always Use Virtual Environments
The single most important best practice for Python development on Linux in 2026 is using virtual environments for every project. The days of installing packages system-wide are over, thanks to PEP 668 and the general recognition that isolation prevents countless problems.
Version Pinning
Always pin your dependency versions in requirements.txt or use a lock file mechanism. This ensures reproducibility across environments:
requests==2.32.3
numpy==2.0.1
pandas==2.2.2Use pyenv for Version Management
Even if you only need one Python version today, installing pyenv gives you flexibility for the future. The ability to quickly test your code against different Python versions is invaluable.
Keep System Python Clean
Never install packages into the system Python using sudo pip. This was bad practice a decade ago and is actively prevented on modern systems. If you need a tool globally, consider using pipx, which installs Python applications in isolated environments but makes them available on your PATH.
Stay Current
Python 3.14 offers significant performance improvements over earlier versions. Unless you have specific compatibility requirements, use the latest stable Python version for new projects.
Conclusion
Installing Python on Linux in 2026 is straightforward, whether you use Ubuntu 26.04, Debian, or Fedora. Each distribution provides official packages for Python and pip, though the specific commands and available versions vary. Ubuntu and Debian use apt to install python3, python3-dev, and python3-venv, while Fedora uses dnf to install python3 and python3-devel. All three distributions support installing multiple Python versions side by side, though Fedora offers the widest selection in its official repositories.
For developers who need precise control over Python versions or need to test against versions not packaged by their distribution, pyenv remains the gold standard. It works identically across all Linux distributions, allowing you to install any Python version from 2.7.18 through 3.14 with a simple pyenv install command.
Virtual environments, whether created with the standard library venv module or with tools like virtualenv, are essential for modern Python development. They isolate project dependencies, prevent conflicts, and work around the externally-managed-environment protections that modern Ubuntu and Debian systems implement.
By following the instructions in this guide, you can set up a robust Python development environment on any major Linux distribution in 2026. Whether you are building web applications, analyzing data, or maintaining legacy systems, the tools and techniques covered here will serve you well.