How to Install PIP on Ubuntu 24.04


PIP is a Python-based package manager to manage Python packages. PIP interacts with the Python Package Index (PyPI) to fetch the package and its dependencies. PIP can install, uninstall, upgrade, or list the Python packages.

A Python package provides the essentials for a specific Python project (multiple modules, that are the core of any Python program). Thus, PIP has a key role in building a Python-based project.

Above all, PIP is an open-source utility and is thus loved by Python developers using Ubuntu (or any Linux distribution).

Keeping PIP’s importance in view, this guide lists the steps to install PIP on the latest LTS of Ubuntu, i.e., 24.04 codenamed Noble Numbat.

Outline:

How to Install PIP on Ubuntu 24.04

Ubuntu by default is equipped with Python3. So, you need to install PIP3 for your Python3. Follow the below steps to install the latest PIP3 on your Ubuntu 24.04:

Step 1: Update the Packages List

Update the core libraries of Ubuntu to get the latest PIP on Ubuntu 24.04:

sudo apt update

Step 2: Install PIP

Here’s the installation command of PIP:

sudo apt install python3-pip

You can check the PIP version using the “pip” and “pip3” commands:

Note: In Ubuntu 24.04, pip and pip3 commands refer to the python3-pip. Python2 is not officially supported anymore on Ubuntu 24.04.

Info: Can We Install Python-2 or PIP-2 on Ubuntu 24.04?

Ubuntu 24.04 strongly depends on Python. Without Python, the system won’t run properly. However, Ubuntu 24.04 only supports Pytnon3, and Python 2 is obsolete. Following this, you won’t be allowed to use/install PIP for Python 2 from the default repositories.

Since Python 2 is no longer usable thus it is recommended not to opt for Python 2 or PIP 2 from untrusted sources.

How to Fix the “error: externally-managed-environment” on Ubuntu 24.04

In the latest Debian release (Debian 12 Bookworm), the Python packages are not installed or managed via PIP in the external environment/globally. Likewise, Canonical integrated this in Ubuntu 24.04 as well. If you use the pip command to manage the Python packages outside the Python environment, you will get the error “externally managed environment” error, as shown below.

Solutions: Either create a Python environment and manage the Python packages inside it or you can globally manage it using the python3-<python-package> command. Let’s demonstrate/practice both cases.

Solution 1: Manage the Python Packages in a Python Environment (Recommended)

While working in a Python-based environment, you can easily manage the Python packages using the pip command. It is recommended to keep your global system clean from unnecessary packages by creating a dedicated/sandboxed environment for Python. Here we will guide you on how you can create a virtual environment and then execute various pip commands inside it.

Creating a Virtual Environment

First, install the “venv” utility:

sudo apt install python3-venv

  • Use the “venv” command to create a virtual environment, i.e., genie_env.
  • Then, source the environment to activate it.
python3 -m venv <env-name>

source env-name/bin/activate

Once the environment is activated, you are good to go with the pip command. Let’s practice it:

General Syntax of the pip Command

The general syntax of the pip3 command and its detailed usage can be found using the command:

pip3 --help

Let’s practice its few important usages:

  • Check the Details/Availability of a Python Package
pip3 show <package-name>

  • Install a Python Package on Ubuntu 24.04

PIP installs the requested package alongside the dependencies. Here’s the syntax:

pip3 install <package-name>

Now, the installation is carried out error-free.

  • Install Multiple Python Packages on Ubuntu 24.04

Instead of installing packages one by one, you can put all the packages in a text file:

and use the below command to install them all at once:

pip3 install -r <text-file>

  • List All the Python Packages on Ubuntu 24.04
pip3 list

  • Upgrade a Python Package on Ubuntu 24.04
pip3 install --upgrade <package-name>

  • Downgrade a Specific Python Package on Ubuntu 24.04
pip install --user package_name==version
  • Uninstall a Python Package on Ubuntu 24.04
pip3 uninstall <package-name>

  • Detailed Usage of the pip in Virtual Environments

Apart from the above-listed examples, the pip command has detailed usage which can be seen using the command:

pip3 --help

That’s how you can manage the Python packages inside a Python-based environment.

Solution 2: Install Python Packages Globally (Not Recommended)

Ubuntu 24.04 allows you to manage the Python packages globally using the apt package manager. It offers very limited control over the Python packages. Thus, it is recommended not to opt for this solution in any case.

However, let’s see the command’s syntax to install/uninstall Python packages externally:

  • Install Python Package
sudo apt install python3-<package-name>

  • Uninstall Python Package
sudo apt autoremove python3-<package-name>

These are the primary commands to install/uninstall Python packages in a global environment.

How to Completely Remove/Uninstall PIP From Ubuntu 24.04

To completely remove the PIP alongside the unused dependencies and the configurations, use the below command:

sudo apt autoremove python3-pip --purge

This is all about dealing with pip on Ubuntu 24.04.

Bottom Line

Ubuntu 24.04 offers the official support of pip for Python3 only. Thus, if you use pip or pip3, you will be navigated to the pip for Python 3 by default. If not, you can use the command “sudo apt install python3-pip”.

In Ubuntu 24.04, Python does not encourage to manage the Python packages in the externally managed environment. Thus, it is recommended to manage Python packages in a Python-based environment (usually a virtual environment).

This post has demonstrated the installation and the basic usage of pip on Ubuntu 24.04.

Print Friendly, PDF & Email
Categories