How to Install Python Pip on Ubuntu

By 

Updated on

4 min read

Install Python Pip on Ubuntu

Pip (Pip Installs Packages) is Python’s package manager. You can use it to install, upgrade, or remove Python packages from the Python Package Index (PyPI) and other sources.

This guide covers installing pip for Python 3 on Ubuntu, verifying the installation, and using it safely in your projects.

Supported Ubuntu Versions

These instructions apply to all current Ubuntu LTS releases, including:

  • Ubuntu 24.04 LTS (Noble)
  • Ubuntu 22.04 LTS (Jammy)
  • Ubuntu 20.04 LTS (Focal)

Before You Begin

Python 3 is included in the base system installation. Ubuntu no longer ships Python 2, which has reached end of life. If you must run legacy Python 2 code, consider using a container or a dedicated legacy environment.

Python modules can be installed globally (accessible for all projects and users) or on a project basis.

Generally, when installing a Python module globally, you should prefer installing the module’s deb package with apt , as these packages are tested to work properly on Ubuntu systems. Use pip to install a module globally only if there is no deb package for that module.

Avoid running pip with sudo outside of a virtual environment. If you need a per-user install without a virtual environment, add the --user flag.

Packages for Python 3 usually start with python3- in their names.

Use pip inside a virtual environment for project work. Virtual environments let you install Python modules for a single project without affecting other projects or your system’s Python setup.

Installing pip for Python 3 (System-Wide)

This section describes how to install pip system-wide. For project work, install packages inside a virtual environment to avoid conflicts.

Installing pip for Python 3 on Ubuntu is straightforward. Run the following commands as root or a sudo user in your terminal:

Terminal
sudo apt update
sudo apt install python3-pip

This command installs pip and its standard Ubuntu package dependencies. Some Python packages with native extensions may still require additional system packages.

Once the installation is complete, verify it by checking the pip version:

Terminal
pip3 --version

The version number you see might be different, but it should look similar to this:

output
pip 24.0 from /usr/lib/python3/dist-packages/pip (python 3.12)

If you prefer to be explicit about the Python interpreter, use:

Terminal
python3 -m pip --version

Using pip in a virtual environment keeps your system Python clean and prevents conflicts. For a full walkthrough of creating and managing virtual environments, see Python Virtual Environments: venv and virtualenv . If you do not have venv yet, install it with:

Terminal
sudo apt update
sudo apt install python3-venv

Create a virtual environment in your project directory:

Terminal
python3 -m venv .venv

Activate it and upgrade pip inside the environment:

Terminal
source .venv/bin/activate
python -m pip install --upgrade pip

Your prompt will show the active environment name. To exit it, run:

Terminal
deactivate

Common Pip Commands

Here are a few common pip commands you will use inside a virtual environment:

Warning
On Ubuntu 24.04, installing packages with pip outside a virtual environment can fail with an externally-managed-environment error. Activate a virtual environment first, then run the pip commands below.
Terminal
pip3 --help
How to use pip

Installing Packages with Pip

The most basic function of the pip tool is to install a package. To install the latest version of a package, run:

txt
pip3 install package_name

For example, to install NumPy:

Terminal
pip3 install numpy

To install a specific version of a package, append == and the version number after the package name:

Terminal
pip3 install numpy==1.26.4

Installing Packages with Pip Using the Requirements File

requirements.txt is a text file containing a list of pip packages and their required versions for a specific Python project.

To install a list of requirements specified in a file, use the following command:

Terminal
pip3 install -r requirements.txt

Listing Installed Packages

To list all the installed pip packages, use the “list” subcommand:

Terminal
pip3 list

Upgrade a Package With Pip

To upgrade an installed package to the latest version, enter:

Terminal
pip3 install --upgrade package_name

Uninstalling Packages With Pip

To uninstall a package, run:

Terminal
pip3 uninstall package_name

To get help for a specific pip command, use:

txt
pip3 command --help

Python 2 (Not Supported)

Python 2 and pip2 are no longer available in Ubuntu repositories. If you need Python 2 for legacy applications, run it in a container or use a dedicated legacy VM.

Conclusion

We have covered how to install pip for Python 3 on Ubuntu and the basic commands for managing packages. While you can install packages globally, using virtual environments is the recommended practice for project development.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page