In this tutorial, we’re going to show you how to install and use Pip (Python) on Ubuntu. This tutorial works for Ubuntu 22.04, Ubuntu 20.04, any other Ubuntu release, and even distros like Linux Mint.
If you tried running a pip command and got a similar error to “Command ‘pip’ not found…”, you need to install pip on your Ubuntu. This tutorial will show you how to install Pip on Ubuntu 22.04, 20.04, 22.10, etc. with step-by-step instructions.
You can check if pip is already installed by running these 2 commands:
pip -V
pip3 -V
If it is installed, you’ll get an output with the specific version of pip you have on your Ubuntu.
Prerequisites for Pip on Ubuntu
This is what you need for this tutorial:
- Ubuntu and SSH access or access to the terminal with the root/sudo user. This tutorial is for the CLI. It’s often used for servers, so you can get a VPS from Linode or any other server provider here.
- Python3 installed on your Ubuntu. You can follow our How to Install Python on Ubuntu tutorial here. Python2 is way past its EOL.
Step 1: Update Ubuntu
The first step, as always, is to update your system. Run the following commands:
apt-get update
apt-get upgrade
Step 2: Install Pip on Ubuntu
Run the following command to install pip on Ubuntu:
apt-get install python3-pip
This assumes that you’re running Python3. If you’re running Python2 (which is unlikely), you’d need to replace “python3-pip” with “python-pip”
And that’s it. Pip is installed for Python 3 on your Ubuntu.
To verify that it’s installed, run:
pip -V
It should give you an output similar to:
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
You can now move on to actually using pip.
How to Use Pip on Ubuntu
Once you install pip, the basic syntax of pip is:
pip <command> [options]
You can run
pip -h
To get more info and more help about pip and its commands and options.
How to Install Pip Packages on Ubuntu
To install a pip package, you need to use the install command:
pip install <package-name>
To get more info and help about the pip install command, run:
pip install -h
You can also install multiple packages that are included in a requirements.txt file (which is often the case) by running:
pip install -r requirements.txt
Assuming you’re already in the directory where requirements.txt is located.
To get a list of all the installed pip packages and their versions, run:
pip list
To uninstall a package, use the following syntax:
pip uninstall <package-name>
pip3 vs pip
pip is basically a link for pip3 by default.
You’ll notice pip and pip3 being used in various tutorials and commands. On the newer releases of Ubuntu, where the default version of Python is 3, you can use “pip”, if you have multiple versions of Python, one of which is Python 2, you will need to use “pip” for Python 2 and “pip3” for Python 3. So, all commands for Python 3 would be “pip3 install <package-name>” instead of “pip install <package-name>”, which would be for Python 2. Other operating systems use pip vs pip3 in different ways.
On Ubuntu, if you’re using Python 3 and you run:
pip -V
pip3 -V
Both commands should give you the same output. If they do, both commands are interchangeable, so you can use whichever is easier.