Save 10%Pay yearly on any plan. 6% half-yearly, 3% quarterly. Help centreWhatsAppTelegram TeamsOpen a ticket

How to Upgrade Pip on Ubuntu

Upgrade pip on Ubuntu the safe way: inside a virtual environment or through apt, and what the "externally-managed-environment" error means.

2 min readBy Swati

Reviewed by the AmazingRDP technical team

Upgrading pip on Ubuntu

Run your Python projects on a server that stays online: a Linux VPS with root access. See Linux VPS from $6.99

pip installs Python packages. The command most guides give for upgrading it, python3 -m pip install --upgrade pip, now ends with an error on current Ubuntu versions. That is deliberate, and there are two clean ways to get a newer pip.

Check what you have

pip3 --version

The answer names the pip version, where it is installed and which Python it belongs to. If pip is missing:

sudo apt update
sudo apt install python3-pip python3-venv

Why the old command fails

From Ubuntu 23.04 on (and Debian 12), the old command answers:

error: externally-managed-environment

Ubuntu itself is partly written in Python. Its Python packages, pip included, are installed and updated by apt. If pip changes those files, system tools can stop working, so Ubuntu now blocks pip from touching the system's Python. Your own projects belong in a virtual environment, where you may upgrade anything.

A virtual environment is a folder with its own Python packages and its own pip, separate from the system.

python3 -m venv ~/venvs/myproject
source ~/venvs/myproject/bin/activate
python -m pip install --upgrade pip
pip --version

The first line creates the environment, the second switches it on for this terminal (the prompt shows its name), the third upgrades pip inside it. Packages you install now go into that folder only. Leave the environment with deactivate.

Way 2: upgrade the system's pip with apt

sudo apt update
sudo apt install --only-upgrade python3-pip

This gives you the newest pip that your Ubuntu release provides. It is older than the newest pip on the internet, and that is fine for the system's own use.

Command-line tools: pipx

For a Python program you want as a command everywhere, such as httpie or black, use pipx. It puts each tool into its own environment for you:

sudo apt install pipx
pipx ensurepath
pipx install httpie

On Ubuntu 22.04 and older

There the block does not exist. Upgrade pip for your user only, without sudo:

python3 -m pip install --user --upgrade pip

The new pip is placed in ~/.local/bin. Open a new terminal so that it is found first.

What not to do

  • sudo pip install --upgrade pip. It overwrites files that apt manages, and later updates can break in confusing ways.
  • --break-system-packages. The option switches the protection off. Its name is honest.

Common problems

  • pip: command not found. Use pip3 or python3 -m pip, or install python3-pip.
  • The version did not change. You upgraded pip in one place and are running another. which pip and pip --version show which one answers.
  • "ensurepip is not available" when creating an environment. Install python3-venv.

Related guides: installing and using FFmpeg in Python, fix "sudo: command not found" in Linux and install 7-Zip on Linux. For a server to run your Python projects, see Linux VPS plans.

Questions

How do I upgrade pip on Ubuntu?

Inside a virtual environment, run python -m pip install --upgrade pip. For the system's pip, run sudo apt install --only-upgrade python3-pip.

What does "externally-managed-environment" mean?

Ubuntu manages the system's Python packages with apt and blocks pip from changing them. Use a virtual environment or pipx.

Should I use sudo with pip?

No. It can overwrite packages the system depends on.

How do I check my pip version?

Run pip3 --version or python3 -m pip --version.