1. Introduction

As system administrators and users, we’ve wanted at some point to install certain software or programs. Naturally, in a Windows environment, we’ll either download the executable installer or get the distributed CD or DVD format. However, in a Linux environment, this is usually not the case. This is because creators distribute their software in .deb files (Ubuntu) or .rpm (Red Hat) format instead, which contain the packages and all other things necessary for installation.

We usually access these files from a package repository. But what is a package repository? In this tutorial, we’ll discuss what package repositories are, their types, and how we can access and manage them in a Linux environment.

2. Package Repositories

Linux distributes most of its software and programs in packages. These packages contain all the necessary files and metadata required to install and run the software successfully on our system.

Therefore, a package repository is a central storage location for pre-compiled software packages. Think of it as an archive where we can access packages through package managers for easy installation.

Package repositories offer a more efficient method of software installation than manually compiling software from source code.

2.1. Types of Package Repositories in Linux

We broadly classify package repositories in Linux into two main types:

  • Official Repositories: Repositories managed by the Linux distribution itself (Ubuntu, Debian)
  • Third-Party Repositories: Independent software repositories that offer software not included in official repositories

Official repositories typically contain a curated selection of well-tested and trusted software packages. Ubuntu further categorizes the official repository into four components:

  • Main: Contains applications that Ubuntu supports and allows us to install and redistribute freely
  • Restricted: Houses proprietary software and drivers whose maintenance and modifications are restricted to the authors
  • Universe: Contains open-source software from public sources. Maintenance and updates of this software appear from the community
  • Multiverse: Houses software that isn’t free and requires a license to use and distribute

3. Using Package Repositories in Linux

We can access, manage, and modify package repositories in Linux through package managers. Each distribution contains a native package manager.

Package managers, like ap**t for Ubuntu and Debian systems, act as interfaces for interacting with repositories. They enable us to search for packages, install them, update existing software, and manage dependencies.

Generally, apt stores the list of repositories in the /etc/apt/sources.list file and in any file with the extension .list in the /etc/apt/sources.list.d/ directory. We can add, delete, and modify software repositories by editing these files, although it’s good practice to back up the configuration before doing so.

To begin with, we can view the configurations in /etc/apt/sources.list using vi:

$ vi /etc/apt/sources.list
# deb cdrom:[Ubuntu 20.04.4 LTS _Focal Fossa_ - Release amd64 (20220223)]/ focal main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ng.archive.ubuntu.com/ubuntu/ focal main restricted
# deb-src http://ng.archive.ubuntu.com/ubuntu/ focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ng.archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb-src http://ng.archive.ubuntu.com/ubuntu/ focal-updates main restricted

## ...
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.

Let’s explain what we see:

  • Lines beginning with # signify comments
  • deb: refers to repositories containing pre-compiled packages that are required for most users
  • deb-src: refers to repositories containing the source code of packages
  • focal: release name or version of the distribution

Furthermore, to add universe and multiverse repositories, we simply delete the # symbols before the corresponding lines and update our configuration after saving using apt-get update. Similarly, to add a third-party repository, we append its source URL at the end of our file:

$ vi /etc/apt/sources.list
# deb cdrom:[Ubuntu 20.04.4 LTS _Focal Fossa_ - Release amd64 (20220223)]/ focal main restricted
...
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirror3.ubuntulinux.nl/ hardy-seveas freenx

Then, we update apt to notify it of our changes. Remember to only add trusted repositories that are known to work on Ubuntu systems.

$ sudo apt-get update

We use sudo to execute the command as the root user.

Additionally, apt commands like apt search, apt install, and apt upgrade help us search, install, and upgrade packages from the repositories.

We can search for a package using apt search:

$ apt search flask
Sorting... Done
Full Text Search... Done
checkpolicy/focal 3.0-1 amd64
  SELinux policy compiler

libselinux1/focal,now 3.0-1build2 amd64 [installed,automatic]
  SELinux runtime shared libraries
...

On the other hand, we can install a package using apt install:

$ sudo apt install python3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3 is already the newest version (3.8.2-0ubuntu2).
...

Finally, we can upgrade all packages to their latest versions using apt upgrade:

$ sudo apt upgrade

This will update all the packages to the latest versions found in the repositories.

4. Benefits of Package Repositories

Package repositories offer several advantages over traditional methods of software installation. The first is efficiency and convenience. Repositories provide a user-friendly way to install and update software. We can leverage package managers to search for desired packages, initiate installations, and manage dependencies automatically.

Another major benefit is security and stability. Repositories maintained by Linux distributions typically undergo security checks to ensure software compatibility with the system. Many repositories employ digital signatures to verify the authenticity and integrity of packages, adding an extra layer of security. As a result, this centralized approach helps maintain system stability and reduces the risk of installing incompatible or malicious software.

Lastly, package repositories ensure consistency and standardization. Within a repository, we have packages that adhere to specific formats and structures, ensuring consistency across the system. Consequently, this allows us to manage software installations and updates easily without worrying about software version conflicts or compatibility issues.

5. Conclusion

In this article, we’ve looked at package repositories in Linux. We defined package repositories as archives that house files and libraries that are needed to install and run programs. Then, we enumerated the types and components of repositories, looking at how we could access and manage them using package managers. Lastly, we explored the benefits of package repositories as opposed to traditional methods of software installation.