How To Install PIP in Linux & Add/Remove Packages

PIP is the de facto package manager for the Python programming language. It allows you to easily install third-party packages that are not installed with Python by default.

 

In this tutorial, we will learn how to install PIP on a Linux system and how to add/remove packages with it.

 

Check if You Already Have PIP

If you are running Python 2.7.9 or Python 3.4 above PIP will already be installed. To check if you have PIP, run the following command:

 

python -m pip --version
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)

 

For Python 3 use:

python3 -m pip --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.7)

 

You can skip to installing a package with PIP if a version is returned using one of the above commands.

 

Installing PIP

On Ubuntu/Debian use the following commands to install PIP:

 

For Python 3 use:

sudo apt install python3-pip python-dev

 

For Python 2 use:

sudo apt install python2-pip python-dev

 

Confirm Installation

Now you can confirm PIP is installed.

 

For Python 2

pip -V

 

For Python 3:

pip3 -V

 

How to Install Packages with PIP

To install packages with PIP type pip install followed by the name of the package to install like this:

 

pip install package-name

 

How to Remove PIP Packages

You can remove Python packages that were installed with PIP like this:

 

pip uninstall package-name
pip install add remove