Have you ever wondered how Linux manages the packages — downloading, installing, and removing them? Well, it all comes under Linux package management.
As Linux is open source, you can find many package managers. And today, we get the chance to learn about Linux package managers in detail.
Throughout the topic, we’ll learn the core concepts surrounding Linux package management, including the definition of Linux package manager, its core concepts, and how it works.
Let’s get started.
What is Linux Package Manager?
A package manager in Linux is a set of software or tools that allows the user to manage packages effectively. The user can install, upgrade, remove, and configure packages using the supported package manager on the Linux operating system.
Function-wise, a package manager deals with packages, an archive file containing computer programs, and other essential files to function, such as package metadata. The package metadata offers information about the packages, including their description, version, and dependencies.
Sounds confusing? Let’s clarify that by learning about the associated package manager core concepts below.
Learning About Core Package Management Concepts
This section will examine the core package management concepts, including packages, dependencies, and repositories.
#1. Packages
A package is at the core of the Linux operating system. Technically, it is an archive file containing an executable binary file, a related configuration file, and information about the dependencies required to run it properly.
To simplify it, you can think of a package as software or an application that can run on the Linux operating system. The package can be a command line oriented or a GUI application. A package can also act as a dependency for other software programs to run.
Another important thing about packages is that they are pre-compiled, meaning the package manager doesn’t have to compile the source code. If we look into the past, you’ll see that software needs to be compiled manually.
- The user must first go to the README file, find all dependencies, and download and install them manually.
- Generally, a makefile or script is included to ease the whole process. This was tedious and also prone to errors.
To ease the process of managing software or services, Linux introduced its package management system.
#2. Dependencies
Linux operating system is complex. It consists of multiple software that depend on each other. For any software to work, it would require some other software or package.
Let’s try to understand it from the development perspective. If you pick up any open-source project, you’ll see it utilizes open-source libraries. After all, it is not wise to develop everything from scratch — re-inventing the wheel is unnecessary.
So, anytime you install a package, it’ll have its listed dependencies. The package manager looks for the list of dependencies and installs all packages or the missing ones.
#3. Repositories
Repositories or repos are virtual online places that list all the packages. These repos are accessible through the internet and help the Linux user to gain access to the packages required during software installation.
Benefits of Using a Package Management System
There are multiple benefits of using a package management system. These include:
- It lets you install new packages easily.
- With a package management system, you can adequately remove old applications.
- Do a clear re-install of the packages. Re-installing packages is a common practice among developers because it ensures that broken configurations or files get fixed automatically without the need to do manual debugging. With a proper package management system, the administrator can confidently re-install the software as the management system handles everything.
- Easily keep your already installed packages updated without any manual intervention. You can set the update to run automatically daily, ensuring your system is protected against Common Vulnerability and Exposures (CVE) or new exploits.
Next, we will discuss how the package manager works.
How Package Manager Works?
A package manager is at the core of the Linux operating system. However, it is also available on Linux.
Package managers are everywhere, including visual editors such as Atom and Visual Studio Code, who have their own. Other popular package managers include PIP, a Python package manager; npm — a JavaScript package manager; and so on.
Also read: What Is Chocolatey and How to Install It
For a package manager to work, it needs access to a working repository. This software repository lists packages. Each package has metadata information, making it easy for the package manager to handle.
So, next time you use the package manager to look for a package, it’ll use the repository’s metadata to learn about the package, such as its name, description, and version.
In the initial interaction, the system’s package manager creates a local metadata cache, which is later used when performing actions such as “update.” — by running commands such as apt update.
Similarly, if you want to install a package, it’ll look into the local metadata cache for information and execute the command based on it.
For instance, if it finds the package you’re looking for, it’ll try to install it by connecting to the repository and downloading it to the system.
Next, it’ll look for the dependencies needed for installing the package. If the package has dependencies, it’ll install them automatically without user intervention.
Like that, the package manager can do other actions, including re-installing packages and removing and upgrading them. The best part about all of these is that everything is configurable. For example, you can configure mission-critical packages for your project to update when you do it yourself.
In short, we can summarize the functions of package managers as below:
- Ensure that the packages are authentic. Also, ensure the integrity of the package is maintained by doing proper checksum and digital certificate authentication.
- Automate package combining for ease of use.
- Make sure to install any dependencies to avoid “dependency hell.”
- Manage packages, including downloading, searching, and installing new or existing software.
Popular Package Managers and Their Comparision
Linux offers access to many good package managers, including APT, YUM, DNF, Pacman, Zypeer, and Portage. Let’s go through them below.
#1. Advanced Package Tool (APT)
APT is one of the most popular Linux package managers, as it comes with Ubuntu and other Debian-based distros.
It uses a dkpg package management tool and a package file format of .deb. It builds on top of dkpg and acts as a front-end for the dkpg package manager. With APT, you can install, search, remove, and manage .deb packages.
Some of the APT commands include apt, apt-cache, and apt-get.
Let’s see some of it in action below.
#install package
$ sudo apt install package_name
#remove package
$ sudo apt remove package_name
#completely purge the package
$ sudo apt purge package_name
# Remove leftover dependencies
$ sudo apt autoremove
#upgrade
$ sudo apt upgrade
# upgrade a single package
$ sudo apt upgrade package_name
#2. DPKG
DPKG stands for Debain-based package management system. The package manager uses the .deb extension. Unlike APT, it cannot automatically install packages and their dependencies.
To install a package with dpkg, you’ll need to use the following command.
$ dkpg -i package_name.deb
Similarly, you can remove a package by running the following command.
$ dkpg -r package_name
#3. YUM
YUM stands for “Yellow Dog Updater, Modified.” YUM has a package file format of .rpm and is available in distributions such as Red Hat Enterprise Linux, CentOS, and Fedora 21.
Like APT, YUM is a high-level package manager but uses RPM (RPM Package Manager) as its underlying package management tool. It offers an easy-to-use interface.
To install a package in YUM, you’ll need to run:
$ yum install package_name
Similarly, you can remove the package by running.
$ yum remove package_name
To update a package, run:
$ yum update package_name
YUM is capable of resolving any dependencies and fetching any updates during installation.
#4. DNF
DNF stands for Dandified YUM. It is a YUM successor and replaces it in most cases. Like YUM, DNF utilizes the RPM package as its underlying package management. However, it offers improvement in better documentation, faster dependency resolution, improved performance, and so on.
#5. RPM
The Red Hat Package Manager (RPM) is used in Red Hat-based Linux operating systems. For example, you can find RPM in CentOS and Fedora. RPM uses a .rpm extension.
To install using RPM, you’ll need to run:
$ rpm -i package_name_rpm
To remove a package, run:
$ rpm -e package_name.rpm
And, to upgrade a package, run:
$ rpm -e package_name
#6. Pacman
Pacman is the package manager for Arch-based Linux operating systems, such as Arch and Manjaro. It uses the .tar.xz file format.
Here, packages are stored and distributed in compressed tarballs. This makes packages small and, hence, easy to distribute and install. Pacman relies on the Arch Build System (ABS) to install packages.
In Pacman, you can install it with the following command:
$ pacman -S package_name
Similarly, you can upgrade all packages in the system using the following command.
$ pacman -Syu
Then, to remove a package in Pacman, use the following command:
$ pacman -Rs package_name
#7. Zypper
Zypper is the package manager for openSUSE. It is a CLI tool that handles packages in the openSUSE Linux distro.
It uses a .rpm package file format, similar to YUM and DNF. However, you’ll rely here on the Zypper interface, which uses the ZYpp libzypp library. This makes Zypper faster compared to other package managers.
#8. Portage
Portage is the package manager for Gentoo distro. The package file format in Portage is .tbz2 — a compressed tar archive or e-build shell script.
Portage works differently compared to other package managers in our list. Here, Portage uses pre-compiled binary packages. The packages are distributed through e-builds – a typical shell script. Here, you also get the Emerge CLI tool, which handles all the shell scripts to install, update, or remove packages.
Which Linux Package Manager Should You Choose?
Most package managers are self-sufficient. In most cases, you’re stuck with the Linux distro you’re using. If you’re starting, you most probably have to use APT.
Advanced users may want to use other package managers. However, the end goal is always to have better software management. So, you can pick any package manager you want, depending on your requirements.
Tips for Efficient Software Management Using Package Managers
As a developer, you must use package managers for efficient software management. This will benefit your software development process, improving your productivity and workflow.
The most significant benefit is that you don’t have to worry about “dependency hell” — a situation where the software doesn’t have access to the packages it requires to run.
The best practices to use package management include:
- Create and manage a proper configuration file listing all the required packages. Alongside the packages, mention the package version to ensure no conflicts occur during implementation. Simply keeping a configuration file can save you from inconsistent environments.
- Use package managers to keep your packages updated to the latest version. This will ensure you don’t suffer from zero-day exploits, as the latest version contains security patches. You’ll also get access to new features and bug fixes. However, before you update packages, run a test environment to see if the new packages break anything. The best way to approach this is to automate the process.
- Create virtual environments to improve package management and their dependencies further.
- Remove packages to improve dependencies. The lean package dependency will enhance security and streamline your project.
- Create proper documentation on dependencies. By doing so, you’re saving hours of pain when handling packages. Always mention the version and make it as detailed as possible. This will help new developers to get on board and also improve maintenance.
Next, we will discuss how to use a package manager.
How to Use A Package Manager?
In this section, we’ll look at examples of how to use a package manager. We’ll use the Advance Package Tool (APT) to simplify things. You will also likely use APT as your first package manager.
Installing Packages
To install a package, you’ll need to use the following command.
$ sudo apt install package-name
Let’s install gimp using the command.
$ sudo apt install gimp
Searching for Packages
If you’re not sure about package availability, you can search for it on the online repository.
For example, if you’re looking for video editing software, you’ll need to search for it as below.
$ sudo apt search “video image”
#output
Sorting... Done
Full Text Search... Done
libgavl-dev/jammy 2.0.0~svn6298-1 amd64
low level audio and video library - development files
libgavl-doc/jammy 2.0.0~svn6298-1 all
low level audio and video library - documentation files
libgavl-ocaml/jammy 0.1.6-1build3 amd64
OCaml interface to the gavl library
libgavl-ocaml-dev/jammy 0.1.6-1build3 amd64
OCaml interface to the gavl library
libgavl2/jammy 2.0.0~svn6298-1 amd64
low level audio and video library - runtime files
The syntax for it as below.
$ sudo apt search “search-term‘
Finding Package Dependencies
You can also use package manager to find dependencies for a package that you wantto install. To list the package dependencies, simply run the following command.
$ sudo apt depends package-name
Let’s see what packages does gimp software depends upon.
$ sudo apt depends gimp
#output
gimp
Depends: libgimp2.0 (>= 2.10.30)
Depends: libgimp2.0 (<= 2.10.30-z)
Depends: gimp-data (>= 2.10.30)
Depends: gimp-data (<= 2.10.30-z)
Depends: graphviz
Depends: xdg-utils
Depends: libaa1 (>= 1.4p5)
Depends: libbabl-0.1-0 (>= 1:0.1.78)
Depends: libbz2-1.0
Depends: libc6 (>= 2.34)
Depends: libcairo2 (>= 1.12.2)
Depends: libfontconfig1 (>= 2.12.6)
Depends: libfreetype6 (>= 2.2.1)
Depends: libgcc-s1 (>= 3.3.1)
Depends: libgdk-pixbuf-2.0-0 (>= 2.30.8)
Depends: libgegl-0.4-0 (>= 1:0.4.34)
Depends: libgexiv2-2 (>= 0.10.6)
Depends: libglib2.0-0 (>= 2.56.2)
Depends: libgs9 (>= 9.10~dfsg)
Depends: libgtk2.0-0 (>= 2.24.10)
Depends: libgudev-1.0-0 (>= 167)
Depends: libharfbuzz0b (>= 0.6.0)
Depends: libheif1 (>= 1.8.0)
Depends: libilmbase25 (>= 2.5.7)
Depends: libjpeg8 (>= 8c)
Depends: libjson-glib-1.0-0 (>= 1.5.2)
Depends: liblcms2-2 (>= 2.9)
Depends: liblzma5 (>= 5.1.1alpha+20120614)
Depends: libmng2 (>= 2.0.2)
Depends: libmypaint-1.5-1 (>= 1.5.0)
Depends: libopenexr25 (>= 2.5.7)
Depends: libopenjp2-7 (>= 2.0.0)
Depends: libpango-1.0-0 (>= 1.29.4)
Depends: libpangocairo-1.0-0 (>= 1.29.4)
Depends: libpangoft2-1.0-0 (>= 1.29.4)
Depends: libpng16-16 (>= 1.6.2-1)
Depends: libpoppler-glib8 (>= 0.44.0)
Depends: librsvg2-2 (>= 2.32.0)
Depends: libstdc++6 (>= 5.2)
Depends: libtiff5 (>= 4.0.3)
Depends: libwebp7
Depends: libwebpdemux2
Depends: libwebpmux3
Depends: libwmf0.2-7 (>= 0.2.8.4)
Depends: libx11-6
Depends: libxcursor1 (>> 1.1.2)
Depends: libxext6
Depends: libxfixes3
Depends: libxmu6
Depends: libxpm4
Depends: zlib1g (>= 1:1.1.4)
Breaks: gimp-plugin-registry (<< 7.20140602+nmu1~)
Recommends: ghostscript
|Suggests: gimp-help-en
Suggests: <gimp-help>
gimp-help-ca
gimp-help-de
gimp-help-el
gimp-help-en
gimp-help-es
gimp-help-fr
gimp-help-it
gimp-help-ja
gimp-help-ko
gimp-help-nl
gimp-help-nn
gimp-help-pt
gimp-help-ru
gimp-help-sl
gimp-help-sv
Suggests: gimp-data-extras
Suggests: gvfs-backends
Suggests: libasound2
liboss4-salsa-asound2
Replaces: gimp-plugin-registry (<< 7.20140602+nmu1~)
Removing Packages
You can also remove packages if you want. To remove a package, you’ll need to use the following command.
$ sudo apt remove package-name
So, if you want to remove the gimp package, you’ll need to run the following command.
$ sudo apt remove gimp
However, this does not remove any dependencies or package configuration. To completely remove it, you’ll need to use the –purge option.
$ sudo apt remove package-name --purge
$ sudo apt remove gimp --purge
Upgrading System Packages
To upgrade system packages, you can run the following command.
$ sudo apt update && sudo apt upgrade -y
Final Words
Package managers are at the core of any Linux distro. It is a critical part and dictates how you manage packages on Linux. With a package manager, you don’t have to worry about dependencies or manually search for packages to install.
Package managers such as APT offer ease of use and handle most of the grunt work, allowing you to focus on what’s essential — i.e., better software development and improved workflow.
More On Linux
-
EditorRashmi Sharma is an editor at Geekflare. She is passionate about researching business resources and has an interest in data analysis.