How to install Python library in Ubuntu Linux

Python is quite a well-known language in today’s world when Artificial Intelligent backed products are booming. It is popular because of its simplicity and versatility. Developers can use it on all popular operating systems to code their applications, the best thing about Python is it provides an ecosystem of executable libraries to provide various packages and modules to make coding of developers easier.

In this article, we learn how to install Python libraries in Ubuntu Linux.

Step 1: Update System Packages

On your Ubuntu Linux, whether it is 22.04, 20.04, or any other, first access your command terminal, the GUI Desktop users can press CTRL+Alt+T to open the Terminal app. Now, it is good practice to run the system update command before installing a new package because sometimes APT couldn’t find the latest version of the available packages due to the old indexed package list.

sudo apt update

Step 2: Install the pip package manager

By default the Python version we have on the latest Ubuntu Linux system is Python3 but we will not have the PIP package manager of Python which is an quite easy way to install various Python libraries.

To install the PIP3 on Ubuntu, the command is:

sudo apt install python3-pip

Note: If you don’t have Python already installed then to get it run: sudo apt install python3

Install the pip package manager

Step 3: Install Python Libraries

As we have the PIP package manager installed on our Ubuntu Linux, the second step is to use it for installing the required library or dependency for our Python project from Python Package Index (PyPI).

To do this, in your command terminal use the following given PIP syntax:

pip install library-of-python

Replace library-of-python in the above syntax with the real name of the library you want to install.

For example, I am a gaming developer and want to install and use the Pygame Python library on my Ubuntu system. To install it, the above command syntax will be used:

pip install pygame

If you get a warningDefaulting to user installation because normal site-packages is not writeable Collecting” the use –user option for giving the permission.

pip install pygame --user

Step 4: Check Library Installation

To check whether the library is actually installed on your system, you can import it using a Python interpreter. For that on your command terminal type:


After that to import the library use the following syntax:

import your_library_name

for example:

import pygame

If there are no errors, the library is installed correctly.

Install Python library on Ubuntu

Step 5: Upgrade Libraries (Optional)

In the future, if there is any update available for your installed library then to apply it simply use the PIP upgrade command, the syntax is given below:

pip install --upgrade library_name

Replace library_name with the name of the library you want to upgrade.

Step 6: Python Library Uninstallation (optional)

There will be a time when you won’t be needed some particular Python library on your system, in that case, if you want to remove it, here is the command to follow:

pip uninstall library-name


pip uninstall pygame


You have seen in this quick article, how simple and easy is to install the Python library on Ubuntu or any other system using its PIP package manager for your Python environment to enhance your programming experience.

Other Articles:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.