How to Install Python pip on Ubuntu

How to Install Python pip on Ubuntu

pip, stands for pip Installs Packages, is a package management system for installing Python dependencies. Unlike Linux’s default software manager, this tool has additional features that make it more flexible and reliable.

For example, pip uses a more comprehensive repository and has dependency resolution to ensure compatibility. This makes pip the preferred tool for managing software during Python project deployment.

This article will explain how to install pip on an Ubuntu virtual private server (VPS) and the basic pip commands for managing Python packages on your system.

pip Installs Packages (pip) is a Python package manager for installing, updating, and removing modules. It lets you select a specific software version, isolate packages in Python virtual environments, and automatically check dependencies. Due to its benefits, pip is the top software for setting up a hosting environment for Python projects.

Prerequisites For Installing pip on Ubuntu

Before proceeding with the steps, ensure you have a VPS running a newer version of the Ubuntu operating system, like 22.04. Otherwise, the installation commands might be different.

Hostinger’s VPS hosting supports various operating systems and software, ensuring smooth pip installation and Python deployment processes.

Users can set up Linux distros and applications in one click using our VPS operating system templates. For example, they can use the Ubuntu 22.04 with Django template to speed up the Python deployment.

Other features also help simplify other server management tasks. The Browser Terminal lets you connect to the VPS directly from your web browser. You can also generate commands for server administration using simple prompts with Kodee, our AI Assistant.

Our VPS plans are suitable for beginners with minimal technical knowledge and experts who require full control over their hosting environment.

How to Install pip on Ubuntu

After purchasing a Hostinger VPS hosting plan and installing Ubuntu 22.04, follow these steps to install pip.

1. Connect to Your VPS and Create a New Account

To run commands on your VPS, connect to the system via the secure shell (SSH) protocol.

Linux or macOS users can use Terminal. However, in this tutorial, we will use the PuTTY client since it is also compatible with other operating systems, including Windows.

After installing PuTTY, open the application and enter your VPS IP address. Click Open and log in as the root user. Hostinger users can find their VPS login information by navigating to hPanelVPSManageSSH access.

Since using root for running Linux commands can be risky due to the lack of confirmation, let’s create a new superuser. Here is the command:

adduser your-username

Enter your new user’s password and other details. Then, grant the account administrative privileges by adding it to the sudo group:

usermod -a -G sudo your-username

Now, let’s switch to the new users using the following command:

su your-username

Once your command-line name changes, enter cd to return to the home directory, and we can proceed with the installation.

2. Update Your System Package Repository

Start by updating your system repository package list to ensure you get the latest software version. Here’s how to do so on Ubuntu:

sudo apt update

Enter the user password and press Y if the command line asks for confirmation.

Although optional, we also recommend installing the latest available patch to avoid incompatibility issues. Here is the command:

sudo apt upgrade

3. Install the Python pip Package

To work correctly, the pip package manager requires Python as the interpreter. Since the programming language is usually pre-configured in Ubuntu, run this command to check if your system has it:

python3 -V

If your command-line interface returns the Python version number, the programming language is already installed.

Otherwise, an error message will show up, and you must manually configure it by running:

sudo apt install python3

Press Y and Enter to confirm the setup. Then, run the following command to install pip and all dependencies for building Python modules:

sudo apt install python3-pip

Now, query the pip version to ensure it is installed correctly using the following command:

pip3 --version

That’s it! Now, you can use pip to manage your Python application’s dependencies.

By default, you should get the latest version from your system’s repository. To update it, run:

sudo pip3 install --upgrade pip

Important! The pip3 package manager will only work on the Python 3 environment. Use pip if you are running Python or Python2.

4. Use pip to Manage Python Packages

Before using pip to install packages, let’s learn how it works.

Unlike Linux’s default package managers that fetch software from the operating system’s repository, this tool uses the more comprehensive Python Package Index (PyPI).

When installing Python packages, pip automatically checks whether all the dependencies are already configured. Otherwise, it installs them first to ensure compatibility and functionality.

To install Python modules using pip, run the following command syntax:

sudo pip install package-name

Replace package-name with your desired software. For example, run the following to install the Scrapy web crawling network tool:

sudo pip3 install scrapy

If you want to configure a specific package version, add the number at the end of your command. For example, the following will set up Scrapy 1.5:

sudo pip3 install scrapy==1.5

You can check all installed pip packages and their version using the list command. To find a specific software, pipe the output to grep like so:

sudo pip3 list | Scrapy

Important! If your command-line interface gives an empty output, check for capitalization since Linux is case-sensitive.

To update a Python package, use the –upgrade option like the following command:

sudo pip3 install scrapy --upgrade

To remove a package from your Ubuntu system, enter the following command but replace package-name with the actual software name:

sudo pip3 uninstall package-name

By default, the uninstall command doesn’t remove the software’s dependencies since other modules might still use them. Keeping unused Python packages might present security risks if not updated and managed correctly.

If you wish to remove the dependencies, list their names in a TXT file and specify it in your command like so:

sudo pip3 uninstall package-name -r dependency_list.txt

We recommend checking the pip documentation to learn other utilities for managing Python packages. Alternatively, ask Kodee to generate commands based on your needs.

Conclusion

pip lets you easily manage Python software packages to prepare your hosting environment before deployment. In this tutorial, we have explained how to install this tool on an Ubuntu server.

After purchasing a Linux VPS hosting plan from Hostinger and installing Ubuntu 22.04, follow these steps:

  1. Access your VPS using an SSH client or Terminal and create a new superuser account.
  2. To get the latest package version, update your system’s repository using apt update and apt upgrade.
  3. Configure Python3 and Pip3 using the apt install command.
  4. Download, list, update, and remove installed packages from the Python Package Index repository using the pip3 command.

To simplify Python package management, use Kodee to help generate pip commands for your tasks.

How to Install Phyton pip on Ubuntu FAQ

To deepen your understanding, this section will answer several questions about installing pip on an Ubuntu machine.

What Is the Command to Check if pip Is Installed on Ubuntu?

To check whether pip is installed, query its version using the pip3 –version command. If your command-line interface returns a number, the software is configured correctly. Otherwise, it will output the “command not found” error.

Are There Any Dependencies for Installing pip on Ubuntu?

Yes. Before installing pip3 on Ubuntu, configure the Python 3 package using the apt install python3 command. Remember to install the correct pip version since pip3 only works on Python 3 environments.

How Do I Update pip on Ubuntu?

To update pip, run the pip3 install –upgrade command in your Terminal. It will fetch the newer version from PyPI instead of your system’s default repository, meaning you don’t need to run apt update beforehand.

Author
The author

Aris Sentika

Aris is a Content Writer specializing in Linux and WordPress development. He has a passion for networking, front-end web development, and server administration. By combining his IT and writing experience, Aris creates content that helps people easily understand complex technical topics to start their online journey. Follow him on LinkedIn.

Author
The Co-author

Hasna A.

Hasna is passionate about tech, culture, and the written word. She hopes to create content that helps people succeed on the web. When not writing, rearranging, or polishing sentences, she enjoys live music and overanalyzing movies.