How to Install Pip on Ubuntu 18.04?

Photo of author

By admin

All the Ubuntu 18.04 version users have been searching for ways to install PIP lately. It’s because this Ubuntu version comes with Python 2 and Python 3 pre-installed. That’s why installing and maintaining Python software packages on Ubuntu requires a package manager tool like PIP.

PIP is a command-line software management system that simplifies the way you install and run any application written in the Python language on Ubuntu. Generally, PIP refers to the Python 2 version, and PIP3 denotes Python 3. Since Ubuntu contains both Python 2 and 3, there are two possible variants of PIP available to install on Ubuntu 18.04.

We have provided a comprehensive guide here for installing, managing, and upgrading PIP and PIP3 on Ubuntu 18.04. Follow the below steps to install using the Ubuntu ‘apt’ package manager. Let’s get started!

Prerequisites:

  • A user account with sudo privileges
  • Access to a terminal window or command line
  • Of course, Ubuntu 18.04 system

Note: If you already have a ‘sudo’ account, skip the next section and move to the installation process directly.

How to Create a New User Account with ‘sudo’ Privileges on Ubuntu?

You might already know that a ‘sudo’ account allows you to run any program with the same security privileges a root user has. If you don’t have an account yet, first add a new user account to run the ‘sudo’ command line. This will create a group and home directory too for the new user. Here is how to do so,

Step 1: At first, log into your system with the ‘sudo’ privileged root user account

Step 2: Next, open a terminal window by pressing Ctrl+Alt+T at the same time

Step 3: Now, create a new user account with the below command (Replace the “newuser” with your one)

adduser newuser

Note: Some non-root users have noticed an error message after entering the above command. Bypass it by entering the below command-

sudo adduser newuser

Step 4: After that, your system will prompt you to enter a password and additional information (Optional)

Step 5: Once you’re done with the password, press Enter to skip the optional step

How to Add an Existing User to ‘sudo’ Group on Ubuntu?

In case you want to add an existing user to ‘sudo’ group in order to give him the root-user privileges, perform the below steps:

Step 1: Open a terminal window first with Ctrl+Alt+T

Step 2: Enter the below command next (Replace the “newuser” with your username)

usermod -aG sudo newuser

Note: If an error message pops up, enter –

sudo usermod -aG sudo newuser

Step 3: Verify the groups the new user belongs to by entering the below command next:

groups new-user

Note: If the new user’s name is not displayed under the ‘sudo’ privilege listing, perform step 4.

Step 4: Finally, switch the users by entering the following command (Replace the “newuser” with the one in Step 2)

su – newuser

Note: When you try to alter the /root directory list, it may show an error. In that case, enter the command- ‘sudo ls /root’.

How to Install PIP for Python 3 on Ubuntu 18.04?

As we’ve already mentioned, Ubuntu 18.04 comes with Python 3 pre-installed but not PIP3. Since you’ve already created a ’sudo’ account, let’s learn the steps to install PIP now.

Step 1: Open the terminal window first by pressing Ctrl+Alt+T together

Note: You can also right-click on the desktop and choose the Open Terminal option

Step 2: Next, you need to update the package list present on the repository, type in the below command for that-

sudo apt update

Step 3: Now, run the following command to install PIP3 and all the other dependencies required for building Python modules-

sudo apt install python3-PIP

Note: Once the installation process is done, you’ll be prompted to confirm it. Type Y and press Enter to confirm the same.

Step 4: Then you need to verify the install, enter the below command to do that-

PIP3 –version

Step 5: Finally, upgrade the PIP3 to its latest version by running the below-mentioned command,

sudo PIP3 install –upgrade PIP

Once done, you’re all set to smoothly run applications written in Python on your Ubuntu 18.04. If you’re using Python 2, then follow the below process to do the same on Ubuntu.

How to Install PIP for Python 2 on Ubuntu 18.04?

To install PIP for Python 2, you’ll follow more or less the same ‘sudo’ command line as shown for the PIP3. But this time, the PIP version will be different. However, first, open a terminal window and then keep performing the below mentioned step-by-step process to install PIP on Ubuntu.

Step 1: First, you have to update the package list present on the repository by entering this command-

sudo apt update

Step 2: Next, run the below command to install PIP and its dependencies to build Python modules

sudo apt install python-PIP

Step 3: You’ll be prompted to confirm the installation. Next, type Y and hit Enter in that case

Step 4: Now you have to verify the install; run the below command for that-

PIP –-version

Step 5: Finally, download the latest version of PIP for Python 2 by running the below command-

sudo PIP install –upgrade PIP

That’s all you need to do to install PIP for Python 2 on Ubuntu 18.04. Knowing only the installation process won’t help you complete your job flawlessly. It is necessary to know how to use PIP properly in order to make the most of it. Learn everything you need to know in the following section.

How to Use PIP on Ubuntu?

Before knowing the usage, let’s address a question: do you install Python modules globally on your Ubuntu system?

If so, then it is recommended to install the Python modules provided by the distribution/package manager.

Yes, when you use PIP inside a virtual environment only, it ensures a completely isolated location for the project and does not affect other Python projects.

Nevertheless, here you will learn a few basic yet effective PIP commands, with which you can easily install packages from the Python Package Index, local projects, version control, and distribution files. Take a look.

Install Packages using PIP:

Run the below command to install the latest version of a particular package:

PIP3 install Enter_Package_Name

To install a specific version of a package, run the following command

PIP3 install Enter_Package_Name==1.5

Install Packages using PIP Requirement Files:

If you want to install packages directly from its ‘requirement.txt’ file, which contains the list of PIP packages and their required versions to run a specific Python project, run the below command-

PIP3 install -r requirements.txt

Upgrade a Package using PIP:

Enter the below command to upgrade a package to its latest version with PIP-

PIP3 install –upgrade package_name

List Installed Packages using PIP:

To list all the installed packages using PIP, follow the below command line-

PIP3 list

Search for a Package using PIP:

If you need to search for a particular package installed on your Ubuntu system, type in this command-

PIP3 search Enter_Search_Term

Get a List of Outdated Packages with PIP:

To get all the outdated packages listed with PIP, enter this command-

PIP3 list –outdated

Uninstall Packages with PIP:

If you want to uninstall a package using PIP, follow the below command-

PIP3 uninstall package_name

Note: If you want to run all these basic commands on Python 2, just replace ‘PIP3’ with ‘PIP’ to get the result.

Apart from this list of basic PIP commands, if you need to know any specific one, you can type in ‘PIP3 –help’ to view the list of all commands and corresponding options.

EndNote

Now, you’ve got the complete overview of how to install PIP on Ubuntu 18.04. Hopefully, it will now be easier for you to run any Python-based application smoothly on your system. However, always remember that PIP is designed to install Python packages from Python Package Index (PyPI). So instead of installing a package globally, it’s better to install a package from the package manager while using PIP. If you’ve further queries, drop a comment in the box below. Stay connected for more tech guides.

Leave a Comment