How to Install pip on Ubuntu 26.04, Debian 13 and AlmaLinux/Rocky Linux 9
Install pip on current Ubuntu, Debian and RHEL 9-family servers, and work with the PEP 668 externally-managed-environment rule using venv and pipx.
This guide shows how to install pip, the Python package installer, on Ubuntu 26.04 LTS and 24.04 LTS, Debian 13 and 12, and the RHEL 9 family (AlmaLinux 9, Rocky Linux 9, CentOS Stream 9). It also explains the externally-managed-environment error that current Debian and Ubuntu releases show when you run pip install outside a virtual environment, and the correct ways to work with it.
All of these systems ship Python 3 only. The Python 2 package python-pip and the plain pip command that older tutorials use no longer exist on Debian and Ubuntu; the package is python3-pip and the safest way to call it is python3 -m pip.
Requirements
- A server running one of the releases above.
- A user with
sudorights (the examples usedeploy). - Python 3, which is part of the base installation on all of these systems. Check with
python3 --version.
Install pip on Ubuntu and Debian
Refresh the package index and install pip together with the venv module, which you will need in the next section:
sudo apt update
sudo apt install python3-pip python3-venv
Confirm the installation:
python3 -m pip --version
The output names the pip version, its location under /usr/lib/python3/dist-packages and the Python version it belongs to. Ubuntu 26.04 pairs pip with Python 3.14; older releases ship older Python and pip versions, but the commands are identical. On Ubuntu, python3-pip lives in the universe component, which is enabled by default on standard server images.
Note that pip --version (or -V) prints the version. The lowercase -v option only means "verbose" and prints the help text when used alone.
The externally-managed-environment error (PEP 668)
On Debian 12 and later and Ubuntu 23.04 and later, this fails:
python3 -m pip install requests
error: externally-managed-environment
× This environment is externally managed
This is deliberate. The distribution places a marker file named EXTERNALLY-MANAGED in Python's standard library directory (for example /usr/lib/python3.14/EXTERNALLY-MANAGED). The mechanism was proposed in PEP 668 and is now part of the Python packaging specifications: when pip runs outside a virtual environment and finds that file, it refuses to install, because packages installed with pip into the system Python can overwrite or conflict with the ones apt manages and break system tools written in Python. The rule also blocks pip install --user. Virtual environments are not affected.
You have three correct options, depending on what you are installing.
Option 1: a virtual environment for a project
A virtual environment is a private directory with its own pip and its own packages. Create one per project, as your normal user:
python3 -m venv ~/venvs/myapp
source ~/venvs/myapp/bin/activate
Inside the environment, pip works without restrictions and without sudo:
python -m pip install --upgrade pip
pip install requests
Leave the environment with:
deactivate
Services and cron jobs do not need to activate anything; call the interpreter inside the environment directly, for example /home/deploy/venvs/myapp/bin/python app.py.
Option 2: pipx for command-line tools
For Python applications you want available as commands (linters, HTTP clients, deployment tools), use pipx. It creates a separate virtual environment for each application and links its commands into ~/.local/bin:
sudo apt install pipx
pipx ensurepath
Log out and back in so the new PATH applies, then install a tool:
pipx install httpie
pipx list, pipx upgrade-all and pipx uninstall httpie manage what you installed.
Option 3: the distribution package
If a script run by the system Python needs a library, install the packaged version. Debian and Ubuntu name these python3- followed by the module name:
apt search python3-requests
sudo apt install python3-requests
What about --break-system-packages?
pip accepts --break-system-packages to override the check. The name is accurate: it installs into the system Python and can break packages that apt owns. Reserve it for disposable containers and images where nothing else depends on the system Python, and never combine it with sudo on a server you care about.
Install pip on AlmaLinux 9, Rocky Linux 9 and CentOS Stream 9
CentOS 7 reached end of life in June 2024 and CentOS Linux 8 in December 2021; the commands below are for their RHEL 9-compatible successors. The default Python on RHEL 9 is 3.9, and its pip is in the AppStream repository, so EPEL is not required:
sudo dnf install python3-pip
python3 -m pip --version
RHEL 9 also provides newer interpreters as separate packages that install alongside the default one. Each has its own pip package:
sudo dnf install python3.12 python3.12-pip
python3.12 -m pip --version
Use python3.12 -m pip or pip3.12 for that interpreter; the unversioned pip and pip3 commands always belong to Python 3.9.
The system Python on RHEL 9 is not marked as externally managed, so pip does not stop you, but the same risk applies: dnf and other system tools depend on it. Do not run sudo pip install. Install per-user or, better, into a virtual environment (the venv module is included with the interpreter):
python3 -m pip install --user requests
python3.12 -m venv ~/venvs/myapp
source ~/venvs/myapp/bin/activate
pip install requests
Everyday pip commands
Run these inside an activated virtual environment:
| Task | Command |
|---|---|
| Install a package | pip install requests |
| Install an exact version | pip install "requests==2.32.3" |
| Upgrade a package | pip install --upgrade requests |
| Remove a package | pip uninstall requests |
| List installed packages | pip list |
| Show outdated packages | pip list --outdated |
| Show details and dependencies | pip show requests |
| Save the exact set of packages | pip freeze > requirements.txt |
| Recreate that set elsewhere | pip install -r requirements.txt |
Keeping pip up to date
The system-wide pip is updated by the distribution together with other packages (sudo apt upgrade or sudo dnf upgrade); distributions mostly backport security fixes rather than move to new pip releases. Do not upgrade it with pip itself. Inside a virtual environment you are free to run the current upstream release:
python -m pip install --upgrade pip
Frequently asked questions
Should I type pip, pip3 or python3 -m pip?
With a single Python installed they run the same program. python3 -m pip is the form that cannot go wrong: it always uses the pip that belongs to the interpreter you name, which matters as soon as a second Python version or a virtual environment is involved. Inside an activated virtual environment, plain pip is unambiguous.
Should I use get-pip.py?
The get-pip.py script from bootstrap.pypa.io is meant for Python installations that have no pip and no package manager, such as a Python you compiled yourself. On a distribution-managed Python it installs a second copy of pip that the package manager does not know about, so use the distribution package instead.
Is it safe to delete the EXTERNALLY-MANAGED file?
It removes the error, but it is the same as passing --break-system-packages to every command, and the file returns with the next Python package update. A virtual environment takes two commands and avoids the problem entirely.
Do I need pip to install Ansible, Certbot or similar tools?
Usually not. Check the distribution repositories first (apt search or dnf search); packaged versions receive security updates automatically. Use pipx or a virtual environment when you need a newer release than the distribution provides.