Skip to content

How to install pip in Ubuntu?

  • by
  • 5 min read

Pip is a tool for installing and managing Python packages. Using this tool, users can search, download, install and manage packages from the Python Package Index otherwise known as PyPI and other available indexes.

Starting with Ubuntu 20.04, Python 3 is included in the base system installation while Python 2 is available for installation from the universal repository. We suggest you stick to Python 3 as Python 2 has been deprecated and no longer receives support. 

For installing Python modules globally, it’s recommended that you use the apt utility. Python 3 packages are prefixed with python3- while Python 2 packages are prefixed with python2-.

You should only use pip to install a package or module if there’s no universal deb file available for the module in question,

Also read: Mint vs Ubuntu: Linux distro comparison


How to install pip for Python 3?

To install pip for Python 3, simply run the following commands as the root or a sudo user.

sudo apt update
sudo apt install python3-pip
How to install pip in ubuntu? | candid. Technology

The aforementioned command will also install all the dependencies required for building Python modules. Once the installation is complete, you can verify the installation by checking the pip version with the following command.

pip3 --version
How to install pip in ubuntu? | candid. Technology

Also read: How to install OpenCV in Ubuntu?


How to install pip for Python 2?

Installing pip for Python 2 requires a few more steps as compared to the aforementioned method. 

Step 1: First up, we’re going to enable the universal repo in Ubuntu.

sudo add-apt-repository universe
How to install pip in ubuntu? | candid. Technology

Step 2: Now update the package index and install Python 2.

sudo apt update
sudo apt install python2
How to install pip in ubuntu? | candid. Technology

Step 3: Once you’re through with that, use curl to download the get-pip.py script.

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
How to install pip in ubuntu? | candid. Technology

Step 4: Finally, you can install pip by running the following command.

sudo python2 get-pip.py
How to install pip in ubuntu? | candid. Technology

Once installed, you can verify the installation by using the following command. 

pip2 --version
How to install pip in ubuntu? | candid. Technology

Also read: How to rename a file in Linux?


How to use pip?

Installing packages with pip is rather easy. For a complete list of basic pip commands, type this in the terminal.

pip3 --help
How to install pip in ubuntu? | candid. Technology

If you’re looking for more information on a particular command, add the command name between pip and the –help flag.

pip3 install --help

The aforementioned command will give you all the information about the pip install command. 

Also read: How to check the list of users in Linux?


How to install packages with pip?

To install a package with pip, type in pip install followed by the package name. For example, to install NumPy, a python library that’s immensely helpful in crunching numbers, use this command.

pip3 install numpy

If you’re looking to install a specific version, use this command instead.

pip3 install numpy ==1.5

Keep in mind to use pip3 to install packages for Python 3 and pip2 to install packages for Python 2. 


How to install packages using a requirements file?

A lot of python programs and repositories will have a requirements.txt file in them that lists out all the dependencies a particular python program needs to be able to run. Instead of installing all these dependencies one at a time, you can install them all at once using this command. 

pip3 install -r requirements.txt

How to list installed pip packages?

Use this command to list all packages you’ve installed using pip.

pip3 list
How to install pip in ubuntu? | candid. Technology

How to upgrade pip packages?

Use this command to upgrade a particular package using pip.

pip3 install --upgrade packageName

How to remove pip packages?

If you’re looking to uninstall a pip package, use this command.

pip3 uninstall packageName

Also read: How to install PHP in Ubuntu?

Yadullah Abidi

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: yadullahabidi@pm.me.

>