How to Install Python Pip on Ubuntu 22.04 LTS

PIP is the standard package manager for installing Python packages. With PIP, you can list, search and download to install packages from the Python Package Index (PyPI). PIP was first included with the Python installer in version 3.4 for Python 3 release and 2.7.9 for Python 2 and is well utilized with many Python projects.

In the following tutorial, you will learn how to install Python + Pip on Ubuntu 22.04 LTS Jammy Jellyfish system using the command line console and various Python Pip installation methods.

Update Ubuntu

First, update your system to ensure all existing packages are up to date.

sudo apt update && sudo apt upgrade -y

Pip 2 vs. Pip 3

For those new to the python programming language altogether, you may wonder what the difference between Pip 2 and Pip 3 is. To sum it up, Pip 2 is a weak link for a particular installer running an older python version, and Pip 3 is an updated version of pip used basically for Python 3+.

It is highly recommended to use Python 3 and PIP3, and you should be upgrading to this as soon as possible.

PIP VS APT Package Manager

A question asked regularly is whether I should use APT or PIP. This is a choice that every user must make. APT is faster however is more outdated, whereas PIP is used to download and install packages directly from PyPI. For those unaware, PyPI is hosted by Python Software Foundation, a package manager that only deals with python packages that are often more updated than those hosted by Canonical through APT. The only drawback of using PIP through PyPI is that the packages can take longer to install.

Install Python

The first installation option is to install the version of Python you would like to work with. Currently, Ubuntu 22.04 LTS features Python 3.10, but you should import the stable PPA repository of Python to get the latest versions of not just Python 3.9 but 3.10, 3.11, and onwards.

Also, the PPA features the last known previous Python versions for those that need a specific version.

Import Python PPA

First, import the PPA with the following command.

sudo add-apt-repository ppa:deadsnakes/ppa -y

Next, run an APT update to reflect the imported PPA to your sources list.

sudo apt-get update

Install Python 2

Python 2 is now at the end of its life, but if you require Python2, which will use PIP2 later on, use the following command.

sudo apt install python2 -y

Next, proceed to the Install PIP and install the corresponding version to your Python installation.

Install Python 3

Next, you can install Python 3, which currently has a few options, most users would opt between 3.9 to 3.10, but you can install whatever version you require.

Install Python 3.9:

sudo apt install python3.9 -y

Install Python 10:

sudo apt install python3.10 -y

Install Python 3.11:

sudo apt install python3.11 -y

Next, proceed to the Install PIP and install the corresponding version to your Python installation.

Install PIP

Install PIP2

To install PIP2, you will need to download the .py script.

curl --output

If you find you are having issues downloading with the curl command, more than likely, you have not installed the package yet.

sudo apt install curl -y

Now execute the .py script.

sudo python2

Example output of dependencies that will be installed:

How to Install Python Pip on Ubuntu 22.04 LTS

Confirm if PIP2 was installed successfully, and run the following command.

pip2 --version

Install PIP3

Next, for most users, you will now install PIP3(For Python 3+) as follows.

sudo apt install python3-pip

Confirm if PIP3 was installed successfully by running the following command.

pip3 --version

Pip Command Examples

Pip has quite an extensive list of packages that can be installed, an easy way to see some of what is available is to run the Pip command list and search. Of course, the commands will work on both Pip 2 and 3 with a slight adjustment.

The tutorial will use some examples below.

First off, to view a list of all pip commands and options, type the following command:

pip3 --help
How to Install Python Pip on Ubuntu 22.04 LTS

Example of using help, example below on getting support on download.

pip3 download --help

Example output:

How to Install Python Pip on Ubuntu 22.04 LTS

To list packages that are available to install, use the following.

pip3 list

Example output:

How to Install Python Pip on Ubuntu 22.04 LTS

If you want to narrow down the list, use the search feature as follows:

pip3 search PACKAGE_NAME

To install a package using Pip, use the following command example.

pip3 install numpy

In the above example, the NumPy package was installed.

Removing a package installed by Pip can be done this time using the uninstall command.

pip3 uninstall numpy

How to Remove (Uninstall) PIP 2 or PIP 3

To remove PIP from your Ubuntu system, follow the below commands depending on which version you have installed.

Remove PIP 2:

sudo python2 -m pip uninstall pip

Example output:

Remove PIP 3:

sudo apt autoremove python3-pip

Example output:

How to Install Python Pip on Ubuntu 22.04 LTS

Comments and Conclusion

In the tutorial, you have learned how to install PIP for Python 2 or Python 3 and search, install, and remove packages.

To find out further information on PIP, visit the official documentation.

Not what you were looking for? Try searching for additional tutorials.

Leave a Comment