Managing Python Versions on Linux Without Breaking Your System
Python 3.15 is out, with lazy imports and UTF-8 by default. Your distribution will not switch its system Python mid-release, and you should not force it to. Here is how to run any Python version you want, safely.
The golden rule: leave the system Python alone
On Linux, /usr/bin/python3 belongs to your distribution. Package managers, installers, firmware tools, and desktop utilities are written in Python and depend on that exact version. Replacing it, or installing packages into it with sudo pip, can break apt, dnf, or parts of your desktop.
Since PEP 668, most distributions enforce this. Try a global install and you get:
error: externally-managed-environment
That is a feature. The fix is never --break-system-packages; it is one of the approaches below.
Option 1: uv (fastest)
uv, from Astral, manages Python versions, virtual environments, and packages, and is very fast. Install it, then:
uv python install 3.15
uv python list
Interpreters go into your home directory as prebuilt binaries; nothing in /usr changes. Start a project on 3.15:
uv venv --python 3.15
source .venv/bin/activate
uv pip install requests
Or let uv manage the project entirely:
uv init myproject --python 3.15
cd myproject
uv add requests
uv run main.py
Option 2: pyenv
pyenv builds Python versions from source and switches between them per directory:
pyenv install 3.15.0
pyenv local 3.15.0 # writes .python-version in the current directory
python --version
It needs build dependencies (a compiler and development headers for OpenSSL, zlib, readline, SQLite, and others) and takes a few minutes per version, but it is widely used and works offline once built.
Option 3: your distribution
Some distributions package several versions side by side:
- Fedora packages multiple versions, for example
sudo dnf install python3.15once available - Ubuntu users often use the deadsnakes PPA for newer versions as
python3.15 - Arch ships the newest Python as the system version quickly, with older ones in the AUR
These install as python3.15, leaving python3 alone.
Option 4: build it yourself
sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
libsqlite3-dev libffi-dev liblzma-dev
tar xf Python-3.15.0.tar.xz && cd Python-3.15.0
./configure --enable-optimizations --prefix=/usr/local
make -j$(nproc)
sudo make altinstall
make altinstall, not make install. altinstall creates python3.15 without touching the python3 command. Our building from source guide covers the general process.
Virtual environments, always
Whichever way you get Python, use a virtual environment per project:
python3.15 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
deactivate
Everything installs into .venv, isolated from other projects and the system. Delete the directory to start again. Add .venv to .gitignore.
Command-line tools: pipx or uv tool
For Python programs you want available everywhere, such as yt-dlp, black, or httpie:
pipx install yt-dlp
# or
uv tool install yt-dlp
Each tool gets its own environment, and its command lands in ~/.local/bin. Make sure that directory is on your PATH; our environment variables guide explains how.
Which should you use?
| Situation | Use |
|---|---|
| New projects, want speed | uv |
| Need many versions, prefer a classic tool | pyenv |
| One extra version, prefer system packages | Distribution package or PPA |
| CLI tools | pipx or uv tool |
| Anything inside a project | A virtual environment |
Quick checks
which -a python3 # every python3 on your PATH, in order
python3 -c 'import sys; print(sys.executable, sys.version)'
If a script suddenly runs under the wrong version, which -a usually shows why: a different interpreter earlier in your PATH.
Frequently Asked Questions
Why should I not upgrade the system Python?
Your distribution’s package manager, installer, and many system tools are written in Python and tested against the version it ships. Replacing or breaking that interpreter can break apt, dnf, or your desktop. Install additional versions alongside it instead.
What does the externally-managed-environment error mean?
It comes from PEP 668. Distributions mark their Python as managed by the system package manager, so pip refuses to install packages into it globally. Use a virtual environment, pipx for command-line tools, or your distribution’s packages instead.
What is the easiest way to install a newer Python?
uv from Astral is the quickest: uv python install 3.15 downloads a prebuilt interpreter into your home directory without touching the system. pyenv builds versions from source and is a long-standing alternative.
What is a virtual environment?
A self-contained directory with its own Python interpreter link and installed packages. Each project gets its own environment, so dependencies do not conflict with each other or with the system. Create one with python3 -m venv .venv or uv venv.
How do I install Python command-line tools globally?
Use pipx install toolname or uv tool install toolname. Each tool gets its own isolated environment, and its command is added to ~/.local/bin, so it is available everywhere without polluting the system Python.
What is make altinstall?
When building Python from source, make altinstall installs it as python3.15 without creating or replacing the generic python3 command. That keeps the system’s python3 pointing at the distribution’s version. make install would overwrite it.