How to Install pip on Ubuntu: A Simple Step-by-Step Guide
Rationale:
If you're a Python enthusiast or developer working on an Ubuntu system, you'll often need external Python packages to enhance your projects. pip
is the most popular package manager for Python, allowing you to easily install and manage these libraries. Whether you're setting up your environment for data analysis, web development, or automation scripting, having pip installed is essential.
Suggested Hook:
Have you ever tried running a Python script only to be greeted by an error saying a module is missing? That’s where pip
comes in handy! Let me show you how easy it is to get this powerful tool up and running on your Ubuntu machine.
What Is pip?
Before diving into the installation process, let’s quickly revisit what pip
is. Pip stands for “Pip Installs Packages” and is the package installer for Python. It allows you to install packages from the Python Package Index (PyPI) with simple commands like:
pip install package-name
With pip
, managing dependencies becomes effortless — no more manual downloads or complicated setups.
Step 1: Check if pip Is Already Installed
Ubuntu often comes with Python pre-installed, but pip might not always be available by default. First, check if you have it:
pip --version
or for Python 3 specifically:
pip3 --version
If you see output like:
pip 21.0.1 from /usr/lib/python3/dist-packages/pip (python 3.8)
then congratulations — pip is already installed!
If you get a “command not found” error, don’t worry; let’s move on to installing it.
Step 2: Update Your Package List
Before installing anything new, it's best practice to update your package lists so you get the latest version available:
sudo apt update
Step 3: Install pip for Python 3
Since Python 2 has reached end-of-life, it’s better to focus on Python 3. To install pip for Python 3 on Ubuntu (20.04, 22.04 and later), run:
sudo apt install python3-pip
You’ll be prompted to confirm installation — hit Y
and press Enter.
Step 4: Verify Installation
After installation completes, verify that pip3 is installed correctly:
pip3 --version
You should see something like:
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
This means you’re ready to install any Python package with ease!
Step 5: Install a Test Package Using pip
Let’s test that pip works by installing a popular library — requests — which lets you make HTTP requests in Python scripts:
pip3 install requests
You should see output about downloading and installing requests along with its dependencies.
To confirm everything worked as expected open the Python interpreter:
python3
Then type:
import requests
print(requests.__version__)
exit()
If no errors appear and you get a version number, success! You’re all set.
Additional Tips
-
If you want to use
pip
as the command instead ofpip3
, consider setting up an alias in your shell configuration (~/.bashrc
or~/.zshrc
):alias pip=pip3
-
For isolating project dependencies, learn how to use virtual environments (
venv
) alongside pip. -
To upgrade pip itself in the future:
sudo -H pip3 install --upgrade pip
Conclusion
Installing pip on Ubuntu is straightforward but super important if you're working with Python regularly. By following these steps—checking existing installations, updating your system packages, installing python3-pip
, and verifying—you’ll have this indispensable tool ready in minutes.
Feel free to bookmark this guide so next time you're missing that crucial library dependency, you can whip out an easy fix with pip install
.
Happy coding!
Did this guide help? Let me know in the comments what projects you're using pip for!