How to Install the pip Package Manager on Ubuntu

  1. Install pip for Python 3 in Ubuntu 20.04
  2. Install pip for Python 2 in Ubuntu 20.04
  3. Example: Install Packages With pip
  4. Upgrade Packages Using pip
  5. Uninstall Packages Using pip

pip is the most widely used tool for downloading and installing packages in Python. From Ubuntu 20.04 and onwards, Ubuntu comes with Python 3 as its default installed Python. However, we can also install Python 2 in Ubuntu 20.04 from the Universe repository.

Install pip for Python 3 in Ubuntu 20.04

To install pip for Python 3 in Ubuntu 20.04, we perform the following steps:

  • Update the package list using the command:
    sudo apt update
    
  • Install the pip using the command:
    sudo apt install python3-pip
    

    It installs pip for Python 3 along with the dependencies.

To verify the installation, we can use the command:

pip3 --version

Output:

pip 20.1.1 from /usr/lib/python3/dist-packages/pip (python 3.8)

Install pip for Python 2 in Ubuntu 20.04

To install pip for Python 2 in Ubuntu 20.04, we perform the following steps:

  • Enable the Universe repository using the command:
    sudo add-apt-repository universe
    
  • Update the package list using the command:
    sudo apt update
    
  • Install the Python 2 using the command:
    sudo apt install python2
    
  • Download the get-pip.py script which is used to install pip for Python 2:
    curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
    
  • Run the get-pip.py script with Python 2 with sudo privilege:
    sudo python2 get-pip.py
    

    It will install pip for Python 2 in Ubuntu 20.04.

To verify the installation, we can use the command:

pip2 --version

Output:

pip 20.0.2 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

Example: Install Packages With pip

To install a package with pip, we use the following command:

pip install <package_name>
pip install numpy

It installs the latest version of NumPy in our system.

To install the specific version of a package, we specify the package’s version in the command.

pip install numpy==1.14.0 

It installs the NumPy with version 1.14.0 in our system.

We can install all the packages listed in the requirements.txt file using the command:

pip install -r requirements.txt

Upgrade Packages Using pip

To upgrade the Python packages using pip, we use the command:

pip install --upgrade <package_name>

Uninstall Packages Using pip

To uninstall the Python packages using pip, we use the command:

pip uninstall <package_name>