Python Installation and Management on Ubuntu 26.04
Learn how to install Python 3.14 on Ubuntu 26.04 from PPA and source code, along with virtual environment management.
Contents
Introduction
Ubuntu 26.04 ships with Python 3.14 by default. For most development projects, this version provided by the system is sufficient. However, certain projects may require different Python versions. This guide explains how to safely install and manage different versions without breaking the system's default Python build.
Checking the System Default
To check the current Python version on your system, run the following command in the terminal:
python3 --versionWarning: Never modify or modify the /usr/bin/python3 file on the system. Do not overwrite. Ubuntu's core tools are dependent on this version.Pip and Venv Installation
You should always use virtual environments to isolate your projects. First, install the necessary packages:
sudo apt update
sudo apt install python3-pip python3-venvTo create and activate a virtual environment:
python3 -m venv project_environment
source project_environment/bin/activateAlternative Versions via Deadsnakes PPA
If you need a different Python version (e.g. 3.13 or 3.15), the 'deadsnakes' PPA repository is the safest method.
- Add the repository:
sudo add-apt-repository ppa:deadsnakes/ppa - Update the package list:
sudo apt update - Install the desired version:
sudo apt install python3.13 - Install the required module:
sudo apt install python3.13-venv
From Source Code Compiling
If you need a very specific configuration, you can compile Python from source code:
- Install the required dependencies:
sudo apt install build-essential libssl-dev zlib1g-dev - Download and extract the source code.
- Configuration:
./configure --enable-optimizations - Compiling and Installation:
make -j $(nproc)andsudo make altinstall
Tip: When installing from source code, be sure to use thealtinstallcommand. Theinstallcommand corrupts the system's default Python version.
Troubleshooting
If you are getting the 'No module named venv' error, make sure that the venv package specific to the Python version you are using (for example python3.13-venv) is installed. If you get the 'Externally managed environment' error, it means you are trying to install packages outside the virtual environment; Be sure to use venv.