Skip to main content

How to install Python PIP in Ubuntu 22/24

4 minutes


This article will take you through how to install PIP on Ubuntu system. You will also learn how to uninstall Python packages and upgrade to the latest version using PIP. The Python PIP will enable you to easily manage Python libraries in your system.

Python Pip(PIP) is the package installer for Python and stands for "Pip Installs Packages" or sometimes recursively as "Pip Installs Python". Pip is utilized for the installation and administration of software programs coded in Python. Using Pip, you can install Python packages from the Python Package Index (PyPI) or from any other sources such as version control systems like Git.

Prerequisites

To install pip3 on Ubuntu, ensure you meet the following requirements.

  • A running local or cloud instance of Ubuntu 22.04/24.04
  • SSH access to the server with sudo privilege. 

 

 

Update package list

First, update the package lists using apt 

$ sudo apt update

Check if Python is installed

Ubuntu has been shipping with Python 3 as the default Python version. Verify the Python version in the Ubuntu system by running the following command.

$ python3 -V
Python 3.10.12

If Python is missing in the system, install it with the following command.

$ sudo apt install -y python3  

Install PIP on Ubuntu

The Python package manager aka PIP is not installed by default. If you try to install a Python package at this stage, a 'command not found' message will be displayed on the screen.

$ sudo pip3 install twilio
Command 'pip3' not found, but can be installed with:
apt install python3-pip

Now install the latest version of PIP with the following command. The command will also install all the dependencies and additional libraries needed by pip.

$ sudo apt install python3-pip
$ pip3 --version 
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
Suricata rule format


The above command will install pip in Ubuntu. Alternately, you can also install pip using get-pip.py. This is how you can do it:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ sudo python3 get-pip.py
$ pip3 --version 
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)

This completes installation of pip on Ubuntu.

Essential PIP commands

To get started with pip, view all the available options with the pip3 command by using the --help switch. 

$ pip3 --help
Usage:   
 pip3 <command> [options]
Commands:
 install                     Install packages.
 download                    Download packages.
 uninstall                   Uninstall packages.
 freeze                      Output installed packages in requirements format.
 list                        List installed packages.
 ...

It is also possible to narrow it down even further by selecting specific command options for showing available choices.

$ pip3 list --help
Usage:   
 pip3 list [options]
Description:
 List installed packages, including editables.
 
 Packages are listed in a case-insensitive sorted order.
List Options:
 -o, --outdated              List outdated packages
 -u, --uptodate              List uptodate packages
 -e, --editable              List editable projects.
 -l, --local                 If in a virtualenv that has global access, do not list globally-installed packages.

Here are some of the essential PIP commands that you are probably interested to tick off

List package

List installed python packages with list option

$ pip3 list

Search package

To search packages from the Python  Package Index, execute the following pip command from the terminal:

$ pip3 search <name-of-package-you-want-to-search>

Install packages

Install a package by passing a package name and a version number as an argument. The following commands shows how to install latest Jira or a specific version with pip. 

$ pip3 install package_name==version_number 
$ pip3 install jira <-- Install latest version of Jira
$ pip3 install jira==1.0.13 <-- Install Jira version 1.0.13

Install packages using requirements.txt

You can also install multiple packages at one go by using a file named as requirements.txt. To use this method, create a file by the name requirements.txt in the root directory of your python project and specify the packages you want to install like below.

$ cat <<EOF >requirements.txt
###### Requirements without Version Specifiers ######
pandas
pillow
numpy
###### Requirements with Version Specifiers ######
pandas == 1.0.0             # Version Matching. Must be version 1.0.0
pillow >= 2.0.0             # Minimum version 2.0.0
numpy != 1.22.4             # Any version other than 1.22.4
EOF 

Now install the package list mentioned in the file requirements.txt by adding -r switch to the PIP command.

$ pip3 install -r requirements.txt

Upgrade package

To upgrade a python package, use the --upgrade switch with the PIP command.

$ pip3 install --upgrade package_name 
$ pip3 install --upgrade pandas

Delete package

To delete a package use the following PIP command.

$ pip3 uninstall package_name 
$ pip3 uninstall matplotlib

 

Conclusion

You've successfully installed Python pip on your Ubuntu system. This powerful tool will simplify your coding tasks and package management. Your development workflow just got more efficient. Continue building and innovating with confidence.

fivestar_rating
No votes yet
Comments