pip is a package management system for managing packages written in Python. It is also known as “pip Installs Packages” or “pip Installs Python.” pip uses Python Package Index (PyPI) for the packages and installs them on your system.

In this post, we will show you how to install and use the pip command in Linux.

Install pip On Debian/Ubuntu

By default, pip is not installed in the Ubuntu and Debian-based operating systems. You will need to install it using the command line.

To install pip for Python 2, run the following command:

apt-get install python-pip -y

To install pip for Python 3, run the following command:

apt-get install python3-pip -y

After the installation, verify the version of pip using the following command:

pip -V

Or

pip3 -V

You should get the following output:

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

Install pip On CentOS, Fedora and RHEL

By default, pip is not included in the software repositories of CentOS/RHEL/Fedora, so you will need to install the EPEL repository to your system.

Run the following command to install the EPEL repository.

yum install epel-release -y
yum install python3-pip

To check the installed version, run the following command:

pip3 -V

You should get the following output:

pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

How to Use pip

To list all pip commands, run the following command :

pip --help

Sample output:

Usage:   
  pip  [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

To install a package with pip, run:

pip install packagename

To remove a package, run:

pip uninstall packagename

To download a Python package without installing it in your system, run:

pip download packagename

To list all packages, run the following command:

pip list

You should see all installed packages in the following output:

Package                Version   
---------------------- ----------
certifi                2019.11.28
chardet                3.0.4     
click                  8.0.1     
dbus-python            1.2.16    
distro                 1.4.0     
Flask                  2.0.1     
idna                   2.8       
itsdangerous           2.0.1     
Jinja2                 3.0.1     
MarkupSafe             2.0.1     
netifaces              0.10.4    
numpy                  1.21.1    
pip                    20.0.2    
PyGObject              3.36.0    
pymacaroons            0.13.0    
PyNaCl                 1.3.0     
PyYAML                 5.3.1     
requests               2.22.0    
setuptools             45.2.0    
six                    1.14.0    
ssh-import-id          5.10      
ubuntu-advantage-tools 20.3      
urllib3                1.25.8    
Werkzeug               2.0.1     
wheel                  0.34.2    

To upgrade a specific package, run the following command:

pip install --upgrade packagename

To display detailed information of any package, run the following command:

pip show flask

You should get the following output:

Name: Flask
Version: 2.0.1
Summary: A simple framework for building complex web applications.
Home-page: https://palletsprojects.com/p/flask
Author: Armin Ronacher
Author-email: [email protected]
License: BSD-3-Clause
Location: /usr/local/lib/python3.8/dist-packages
Requires: Jinja2, Werkzeug, itsdangerous, click
Required-by: 

Conclusion

In the above guide, we explained how to install pip on Linux. pip is a very useful utility that simplifies the process of Python package installation. Give it a try on your dedicated server from Atlantic.Net!