How to Install pip on Ubuntu 20.04

install pip python ubuntu 20.04

In this article, we will talk about pip, how to install it as well as how to use it on an Ubuntu 20.04 VPS. To begin, we’ll need to clarify what pip actually is. Pip is a package manager for Python. It’s normally used to install and manage Python modules on your system.

installing pip on ubuntu 20.04

In case Python is new to you as well, Python is a high-level object-oriented programming language that is becoming increasingly popular over the years. Python is widely used in software development, system administration, scientific and numeric data analysis, and much more.

Both Python 2 or Python 3 can be installed on Ubuntu 20.04. However, with Ubuntu 20.04, the default version is Python 3. If for some reason you need Python 2 along with its version of pip, don’t worry, we’re covering that in this tutorial as well.

Pip is not installed by default on Ubuntu – however, the installation is quite quick and simple. Let’s start with the installation.

Getting Started

First, you need to login to your Ubuntu 20.04 VPS via SSH as the root user account, or as a user with sudo privileges:

ssh root@Server_IP_Address -p Port_Number

Of course, you will need to replace Server_IP_Address and Port_Number with your actual server IP address and SSH port number.

By running the following command, all installed packages will be updated and upgraded:

apt update && apt upgrade -y

You can also restart your server to ensure that all of the latest configuration files get read and used.

install pip on ubuntu 20.04

Install pip for Python 3

We assume that you already have the default Python version installed on your server. To check if Python 3 is already installed on your server, use the command below:

python3 -V

You should get the following output:

root@ubuntu20:~# python3 -V
Python 3.8.2

Before proceeding with the installation of pip, it is a good idea to confirm whether pip is already installed on your server. You can do this with the command:

pip3 -V

If you get the following output:

Command 'pip3' not found

This means that pip3 is not installed on your server. You can install pip3 by executing this next command:

apt install python3-pip

By executing the above command, all of the dependencies required for pip will be installed along with PiP. When the installation is complete, you can validate the installed pip with the command:

pip3 --version

You should have an output similar to the following:

root@ubuntu20:~# pip3 -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

Install PiP for Python 2 (optional)

If for some reason you want to use Python 2 instead of the default Python 3 version, you can follow this section of the article.

To install Python 2 you can run the command:

apt install python2
installing pip on ubuntu 20.04

Since PiP for Python2 is not available in the Ubuntu 20.04 repository, in this step we will use the get-pip.py script. Use the following command to download the get-pip.py script:

curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py

Now you can execute the script with python2 to install pip for Python 2.

python2 get-pip.py

Once the installation is complete, you can verify the pip version with:

pip -V

If you get the following output:

root@ubuntu20:~# pip -V
pip 20.1.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

Then you have the correct version of pip installed for Python 2.

How to Use pip3

In this step of the article, we will show you a few useful basic pip commands. Now that pip is installed, you can try to use it.

The basic syntax for pip3 is the following:

pip3 <command> [options]

The following examples are the most commonly used pip3 commands.

If you want to install a package:

pip3 install package_name

You can list all installed packages:

pip3 list

Or you can search for a package:

pip3 search package_name

If for some reason you want to remove/uninstall some package, you can use the command:

pip3 uninstall package_name

You can find more options and usage examples by running the help command:

pip3 --help

Output:

Usage:
  pip3 <command> [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.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
  --log                       Path to a verbose appending log.
  --proxy                     Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries                   Maximum number of retries each connection should attempt (default 5 times).
  --timeout                   Set the socket timeout (default 15 seconds).
  --exists-action             Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host              Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS.
  --cert                      Path to alternate CA bundle.
  --client-cert               Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir
                              Store the cache data in. 
  --no-cache-dir              Disable the cache. --disable-pip-version-check
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
  --no-color                  Suppress colored output
  --no-python-version-warning
                              Silence deprecation warnings for upcoming unsupported Pythons.

And if you are interested in some specific command details, you can use the following command:

pip3 <command> --help

Congratulations! You have successfully installed pip on your server and learned a few basic commands for pip.


installation pip on ubuntu 20 04

Python and pip management is simple, however getting your Python applications to run properly can be a frustrating experience. Our managed Python hosting gives you peace of mind – our support team of experts will get any Python application that you need up and running immediately. They can also maintain your server and perform any requests that you have, all included with the cost of the VPS.

Have any suggestions or questions that you want to share? Leave them in our comment section! You can also share this tutorial on social media by using our share buttons.

Leave a Comment

To prove you are human please solve the following *