How to Install Pip in Ubuntu

How to Install Pip in Ubuntu

Python allows you to plenty of things thanks to its vast library of modules and packages. Most of these packages need to be installed using a package manager such as pip, the default package manager of python. In most cases, python ships with pip utility. It is installed alongside python during installation. But sometimes you may find that your Python’s pip utility has become outdated or corrupted. In such cases, you need to install pip in Ubuntu.

How to Install Pip in Ubuntu

We will look at how to install pip in Ubuntu, for Python 3 as well as Python 2.

Install Pip for Python 3

Open terminal and run the following command to update your Ubuntu package manager.

# sudo apt update -y

Next, run the following command to install pip for Python 3.

# sudo apt install python3-pip

When you run the above command, Linux will also download and install related dependencies and other required packages.

Once pip is installed, run the following command to check its version.

# pip3 --version 

Most latest Ubuntu versions come with Python 3 so it is easy to directly install Pip. Please note, the above command will install the latest version of pip3. If you want to install a specific version of pip3 then mention the version number of pip in ‘apt install’ command as shown below.

# sudo apt install python3-pip==<version number>

Install Pip for Python 2

Since Ubuntu does not ship with Python 2 these days, installing pip for Python 2 is takes a few more steps.

For this, we will first add the required python repository.

# sudo add-apt-repository universe

Next, update package index using the following index.

# sudo apt update -y

Most likely, your system may have only Python 3 and not Python 2. So you will need to install Python 2 also as shown below.

# sudo apt install python2

Now that you have installed python2, you need to download and use get-pip.py script. You can do it using curl command.

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

Now we will use get-pip.py to install pip for python 2. Please note, if you run the above script as root, it will be installed for all users on your system. If you want to install it for specific user, log in as that user before running get-pip.p script.

We will install pip for all users using the following command.

# sudo python2 get-pip.py

Once you run the above script, it will also install other packages and dependencies required by pip. After installation, you can check if it is properly installed using the following command.

# pip2 --version

Please note, if you are using pip 3, then you need call ‘pip3’ and if you are using pip 2, you need to call ‘pip 2’ in your commands.

In this article, we have learnt how to install pip in Ubuntu.

Also read:

How to Redirect Subfolder to Root in Apache
How to Block User Agent in Apache
How to Enable IPv6 in Apache Web Server
How to Change Root Password in Ubuntu
How to Upgrade Django Version

Leave a Reply

Your email address will not be published. Required fields are marked *