Applies to: Ubuntu 24.04 (Python 3.12), Debian 13 (Python 3.13) and AlmaLinux 9 (Python 3.9 plus 3.11, 3.12 and 3.13); tested on all three
Linux distributions depend on their own Python for system tools, so “updating Python” means adding a newer version next to the system one, and using virtual environments for your projects. Replacing the system python3 can break the package manager and other tools.
Which Python do you have?
python3 --version
In our tests: Ubuntu 24.04 has Python 3.12.3, Debian 13 has 3.13.5, and AlmaLinux 9 has 3.9.25 (its dnf runs on /usr/bin/python3.9).
AlmaLinux and Rocky Linux 9: install a newer version side by side
dnf list --available "python3.1*" sudo dnf install python3.12 python3.12-pip python3.12 --version # Python 3.12.14 python3 --version # still Python 3.9.25
Python 3.11 and 3.12 come from AppStream; 3.13 is in EPEL. Start the new version as python3.12; don’t change /usr/bin/python3 or the alternatives system.
Ubuntu and Debian
Use the version your release ships, or move to a newer release for a newer default Python. Other versions per user can come from tools such as pyenv or uv, or from Docker images like python:3.14.
Upgrade pip the right way: in a virtual environment
python3.12 -m venv ~/venvs/app # or: python3 -m venv ~/venvs/app source ~/venvs/app/bin/activate python -m pip install --upgrade pip pip --version # pip 26.2.1 in our test
Everything you install then stays inside ~/venvs/app and can’t break the system.
The errors you will meet on Ubuntu and Debian
error: externally-managed-environmentwhen you runpip installoutside a virtual environment: the system Python is managed by apt. Use a virtual environment, orsudo apt install python3-<name>for packages the distribution provides.The virtual environment was not created successfully because ensurepip is not available.Install the venv module first:sudo apt install python3-venv.
Don’t work around these with sudo pip install or --break-system-packages on a server: it mixes pip files into apt-managed folders.
Run an app with the new Python
Point your service or cron job at the virtual environment’s interpreter, for example /home/app/venvs/app/bin/python app.py, so it doesn’t depend on the shell being activated.
Related: install pip on Debian and pip on Windows. Safe system updates: update packages with apt and dnf.
Ucartz services for this topic
- KVM VPS hosting: NVMe SSD and full root access, with Free Basic Managed Support.
- Unmanaged dedicated servers: full root access and free IPMI KVM, with Free Basic Managed Support.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
