How to APT Install Python pip2|pip3| on Ubuntu 22.04|20.04

Posted March 28, 2024
How to APT Install Python pip2|pip3| on Ubuntu 22.04|20.04

Are you using Python on your Ubuntu 22.04|20.04 machine? Python will need pip (pip2|pip3) so you can install any Python related packages and run scripts within your Ubuntu server.

If you have you used Python, I’m sure you are familiar with Pip, the Python management command-line tool. Pip stands for “Pip Installs Packages”. If you are using Python2 or Python3, you will need pip2 (sudo apt install python-pip) or pip3 (sudo apt install python3-pip) respectively.

In this comprehensive guide, you will learn how to use Ubuntu APT to install and get Python pip2 and pip3 ready on your Ubuntu 22.04/20.04 LTS. You will learn:

  • How to install pip2 and pip3 based on Python versions Python2 or Python3 on Ubuntu.
  • How to use pip to install, uninstall, and manage Python packages.
  • How to update and upgrade pip versions on your Ubuntu.
  • Uninstalling and Removing pip from the Ubuntu system.
  • The differences between Python pip (pip2) and pip 3

Ready? Now, dive in and get Python Pip ready on your Ubuntu 22.04|20.04 like a Pro.

The Prerequisites of Installing Pip on Ubuntu

  • Pip uses Python. You must have either Python2 or Python3 installed on your Ubuntu machine. Use the following command to conform so:
# Check python2
# Expected Output: Python 2.7.x
python --version
# Check Python3
# Expected Output: Python 3.8.x
python3 --version
  • Ensure you have Ubuntu sudo privileges for your installed Python and access to an Ubuntu machine terminal.

The Differences Between Python pip (pip2) and pip 3

If it is your first time using pip, pip has pip2 and pip3. They serve similar purposes but are associated with different Python versions (2.x and 3.x).

You need to know Python 2.x has reached its end of life and is no longer officially supported. pip3 is the right choice. I have prepared the following table to online the main differences between these two:

Feature Python pip (pip2) Python pip3
Purpose Install and manage Python 2.x packages Install and manage Python 3.x packages
Command Usage pip command without version specification pip3 command explicitly used for Python 3.x packages
End of Life Python 2.x reached end of life in January 2020 Active development and support
Current Usage Diminished support due to end of life for Python 2.x Preferred choice for managing Python packages

Installing Python pip 3 on Ubuntu 22.04|20.04

Almost every Ubuntu OS has Python installed. In this case, you will likely have Python3 installed as such:

APT Install Python pip2|pip3| on Ubuntu 22.04|20.04

In this case, you will need to only let Ubuntu install pip for Python 3. First, ensure you update the Ubuntu package index.

sudo apt update
sudo apt upgrade -y

Next, use the APT command as follows. This should get Ubuntu ready to install Pip:

sudo apt install python3-pip -y

Ubuntu will list all the packages that pip3 will require and they will get installed all together.

Installing Python pip 3 on Ubuntu 22.04|20.04

How to Confirm Pip on Ubuntu

Once you have the above command successfully, you should check and confirm if Ubuntu has your pip manager okay. Use the following command:

sudo pip3 --version

Installing Python pip 3 on Ubuntu 22.04|20.04

And there you have it. Pip3 is ready to manage Python. pip is installed on your Ubuntu system.

Installing Python pip 2 on Ubuntu 22.04|20.04

If you have Python 2 installed on Ubuntu, you can use pip 3. You need pip 2. You will use the following command:

sudo apt install python-pip -y

To confirm the pip 2 version, you will need to twist your previous command and check pip 2 only:

sudo pip2 --version

Installing Python pip 2 on Ubuntu 22.04|20.04

How to Install Pip Downloading the Python Script

Bootstrap has all Python installation scripts. It includes pip.

Installing Python pip 2 on Ubuntu 22.04|20.04

The only thing you need is to use the wget command and Download the get-pip.py file to Ubuntu as follows:

wget https://bootstrap.pypa.io/get-pip.py

Installing Python pip 2 on Ubuntu 22.04|20.04

Used an ls command to confirm you have the get-pip.py file ready:

ubuntu@:~$ ls
get-pip.py

Next, run the Python script to get the downloaded script pip package ready on Ubuntu:

Installing Python pip 2 on Ubuntu 22.04|20.04

How to Update and Upgrade Pip on Ubuntu

Let’s say you have pip ready on Ubuntu and you want to get the latest version to be available on Ubuntu. In this case, you will have to Upgrade the available version to the latest version:

Let’s consider Python 3 and Pip 3 as follows:

ubuntu@:~$ sudo pip3 --version
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)

Here I have pip version 22.0.2. Now, I need to run the following upgrade pip command and get a later version:

sudo pip3 install --upgrade pip

How to Update and Upgrade Pip on Ubuntu

Python will get pip version 24.0 (at the time of writing this Ubuntu Post) and update it. The sudo pip3 --version command should confirm this change:

How to Update and Upgrade Pip on Ubuntu

The same process goes the same if you have Python pip 2 installed. You will use the following command and upgrade pip:

sudo pip2 install --upgrade pip

Using Pip to Install and Manage Packages on Ubuntu

The job of Pip is to manage Python packages. Let’s check examples of how to use pip 2 and pip 3 for Python 2 and Python 3 respectively.

  • Let’s use pip to install Python packages. Here is an example:
# Python 3
pip3 install numpy
## Python 2
pip install numpy

Note: If you are using Python2 and pip2, all the following commands will work the same. However, you will need to use pip and not pip3 followed by your command instructions

pip3 for Python 3 packages and pip for Python 2 packages. But also know Python 2 is no longer officially supported

  • Use the --upgrade flag to upgrade a package to the latest version:
pip3 install --upgrade numpy
  • Uninstall Packages using the uninstall command:
pip3 uninstall numpy
  • To list installed packages use list as such:
pip3 list

How to Uninstall and Remove Pip from Ubuntu

Let’s say you no longer want Ubuntu to have pip installed on your machine. You will need to uninstall and remove it.

For Python Pip 3 use auto-remove and purge python3-pip as such:

sudo apt autoremove -purge python3-pip

Using Pip to Install and Manage Packages on Ubuntu

If you are using pip2, the following is your command:

sudo apt autoremove --purge python-pip

Conclusion

You now have Pip in Ubuntu 22.04|20.04. You only need sudo apt install python3-pip to get Pip ready. This guide helped you Learn:

  • How to install pip2 and pip3 based on Python versions Python2 or Python3 on Ubuntu.
  • How to use pip to install, uninstall, and manage Python packages.
  • How to update and upgrade pip versions on your Ubuntu.
  • Uninstalling and Removing pip from the Ubuntu system.
  • The differences between Python pip (pip2) and pip 3.

I hope you found the guide helpful.

How to APT Install Python pip2|pip3| on Ubuntu 22.04|20.04

Written By:

Joseph Chege