Package manager in Linux

In general terms and without going into too much detail, a package in Linux consists of a collection of files that allow the installation of a program and its related tasks, such as dependency scanning, pre-installation, and so on. Therefore, a package is not the application as such but the collection of files needed to install it.

The use of packages attempts to solve the problem of interoperability between distributions thanks to a small metadata file that acts as a manifest of dependencies that must be met for the packaged software to run correctly on a given computer. So for example, we can have a package for Ubuntu 20.04 that might work fine on Debian 11. If not, we will be informed during the installation process.

Although working with packages may seem simple, it is not. Imagine managing dependencies manually, it would be crazy. Fortunately, package managers were born to make it easier to use and work with packages.

So, package managers are utilities present in every distribution that automate the process, list other packages available in the repository, and display information about their dependencies. There is a problem, however, and that is that package managers cannot be part of the kernel. This means that their particular operation depends on the distribution you are on and the package manager you have chosen.

This is why there are different package managers in the Linux world. So we will try in this post, to explain the most popular and known by almost everyone.

APT: The Debian and Ubuntu Package Manager

According to the Wikipedia

Advanced Package Tool, or APT, is a free software user interface that works with core libraries to handle the installation and removal of software on Debian, and Debian-based Linux Distributions.

It provides command-line tools for searching, managing, and querying information about packages, as well as low-level access to all features provided by the libapt-pkg and libapt-inst libraries which higher-level package managers can depend upon.

This package manager is one of the best-known package managers because it is used by Debian, Ubuntu, Linux Mint, Elementary OS so we are talking about the most popular distributions out there.

Using APT on Debian, Ubuntu and derivates

Since APT is a CLI program, then we have to run it in a terminal environment.

To install a package just run the following command with root privileges.

apt install [package_name]

The program will then read the information in the official repositories of the distribution and calculate the necessary dependencies for the installation.

Now for the package information to be correct, it is necessary to refresh the repositories for any changes.

apt update

As you can imagine, you can install several applications in one command. This is accomplished by specifying each of the separate packages.

apt install [package1_name] [package2_name] [...]

If for some reason you need to reinstall a package, just run

apt install – reinstall [package_name]

In case you want to uninstall, instead of install then use the remove option.

apt remove [package_name]

Similarly, you can remove several packages at once.

apt install [package1_name] [package2_name] [...]

Another useful feature of package managers, and thus APT, is that you can keep your distribution up to date with a couple of commands.

apt update
apt upgrade

This last command updates all the packages installed on the system to the latest version at the time the command is executed. Of course, with one caveat, if an upgrade requires the installation of a new package, that upgrade is not performed.

To avoid this last behavior, APT has another option.

apt full-upgrade

That is, this command upgrades all packages installed on the system to the latest version and if any upgrade requires the installation of a new package, the new package is installed and the upgrade is complete.

Some APT advanced options

Although the remove option is sufficient to remove a package, it does not remove its configuration files. For this, there is purge.

apt purge [package_name]

So with this command, you can remove the package and its configuration files.

As we install packages, other packages are installed as dependencies. If these are no longer needed, then it is a good idea to remove them and save space. To do this, there is autoremove.

apt autoremove

Combining it with purge can be quite efficient.

apt autoremove -purge

This way you can remove auto-installed packages that are no longer needed, including configuration files.

On the other hand, if you want to search for a package or related packages, search is a great help.

apt search [package]

Or display information about a package:

apt show [package_name]

Finally, clearing the package cache is vital so that we can save disk space. This cache fills up every time we install a package, so it is not enough to just install it, it must also be removed from the hard disk.

So,  you can do it running

apt-get clean

So, this way you can use APT without any problems.

Aptitude is another package manger for Debian

Now it’s time to talk about Aptitude. One of the advantages of Debian systems is that we have several options for almost everything. In this case, we will also discuss another package manager that aims to rival APT.

According to Debian

Aptitude is a Ncurses and command-line based front-end to numerous Apt libraries, which are also used by Apt, the default Debian package manager. Aptitude is text-based and runs from a terminal.

For many veteran Debian users, this command has better control and handling of dependencies than the `apt` command. If the aptitude command is run without options it raises an interactive console mode interface.

If we are talking about an application that is intended to rival APT, then we are talking about a package manager that performs all the operations you would expect it to do such as installing, uninstalling, searching, and handling package dependencies in Debian.

So let’s go for it.

Using Aptitude another package manager in Linux

The way Aptitude works are quite similar to APT. It does have a few differences though.

To refresh the local database with that of the remote repositories, just run with root privileges

aptitude update

To update the distribution completely, you have two options. The first is

aptitude upgrade

This command will upgrade all the packages in the system along with their dependencies. Let’s say it’s the normal upgrade that we would normally do.

However, Debian’s recommended method of upgrading the distribution using Aptitude is as follows

aptitude safe-upgrade

This way we can be more confident when upgrading packages.

To install a package you can run

aptitude install [package_name]

As with APT, you can install several packages at once.

aptitude install [package1_name] [package2_name] [package3_name] [...]

If you want to uninstall a package from the system then you have to run

aptitude remove [package_name] 

As with the installation, you can remove several packages simultaneously.

aptitude remove [package1_name] [package2_name] [package3_name] [...]

If you want to remove the package as well as its configuration file, use the `purge` option.

aptitude purge [package_name]

To search the repositories you can run

aptitude search [package_name]

Also, you have the option to request information about a particular package.

aptitude show [package_name]

As you can see, the process is similar to APT.

Dpkg command

The `dpkg` command is a central software management tool but is rarely used directly in Debian and many other Linux distributions that use the Debian package format. This command is what installs, uninstalls, and retrieves package information. Let’s say it is the basic tool and the backend while APT or Aptitude is the front-end.

Dpkg is used from the command line, to use this command we must add several parameters and options, as we will see below.

Using dpkg on Linux

For installation, however, APT needs a special repository to find the available packages. But in the case of `dpkg` these are individual packages that we can download. What APT does is download them and have `dpkg` install them.

So, to install a package you can run

dpkg -i [package_name].deb

These `.deb` packages can be obtained from the websites of some applications that distribute their applications this way. Another way is to get packages from debian.pkgs.org.

To remove it, then you have to run

dpkg -r [package_name].

And if you want to list all the packages installed on the system, you have to run

dpkg -l

Another useful option is to check the contents of a package. This will help us to know exactly what we are installing on the system as well as to know the whole structure of it.

dpkg -c [package_name]

Also, you can check if a package is on the system

dpkg -s [package_name]

Now, when a package is installed, you can find out where it is located on the system.

dpkg -L [package_name]

If you have several packages in a single directory, you can do a recursive install.

dpkg -R – install [directory]/

Also, you can decompress a package but without installing it

dpkg – unpack [package_name]

Another option, is to reconfigure a package when you need to re-set its configuration files

dpkg – configure [package_name]

As you can see the operation of dpkg is somewhat easier but with fewer options because for that there is APT or Aptitude.

Portage: A package manager for Gentoo

Even though Gentoo is not as popular as it used to be and has fallen a bit behind Ubuntu or Debian in popularity, it is still held in high esteem by the community.

Portage is not only the package manager for Gentoo but also for other Gentoo-based distributions like Sabayon or Calculate Linux. Portage is completely written in Python and Bash and, therefore, completely given to the users as both languages are interpreted.

For Gentoo and derivatives, there is a command-line program called `emerge` that will allow us to use Portage in a comfortable, fast and easy way.

Using Emerge and Portage

The operation of Emerge and therefore Portage is somewhat different from other package managers. However, there are still a lot of similarities. Let’s get to it.

To synchronize the local database with the remote repository, run from a terminal and as the root user.

emerge – sync

Also, the emerge-webrsync tool retrieves and installs the most recent snapshot of package information issued directly by Gentoo on your system. This option is useful when the mirror you are using is not available.

emerge-webrsync

To search for a package within the repositories, run

emerge -s [package_name]

You can do a deeper search by looking in the package descriptions as well.

emerge -S [package]

To install a package along with its dependencies you can run

emerge [package_name]

Before that, you can even show the dependencies of the package without installing it.

emerge -p [package_name]

To uninstall a package with its dependencies, you can run

emerge -Ca [package_name]

In case you want to upgrade the system, you have to run

emerge -ua world

This command updates the system but not necessarily the dependencies.

If you want the dependencies to be updated as well, then you have to do a deep update.

emerge -uaD world

Finally, it is recommended to uninstall the orphaned dependencies from the system. To do this, run the following three commands

emerge -uaDN world
emerge – depclean
revdep-rebuild

Where you update, clean the dependencies, and finally apply the changes.

YUM the CentOS 7 package manager

One of the reasons why YUM is still worth talking about is because it is the package manager used by CentOS 7 and this system is still present on many servers worldwide.

YUM, in other words, “Yellowdog Updater, Modified”, is used to manage RPM packages in several Linux distributions, including those derived from CentOS 7. This package manager replaced YUP to give us a faster and more reliable alternative.

As expected, YUM automatically determines the necessary dependencies and what needs to be done to install packages. You can also search for, remove or upgrade packages.

So, let’s take a look at it.

Using YUM package manager

Like any other package manager, we can use it from the terminal. So, open one, and let’s get started.

To synchronize the local database with the remote repositories and update the distribution, just run

yum update

You can also update just one package

yum update [package_name]

Or several:

yum update [package1_name] [package2_name] [...]

Now, if you want to install a package, you can do so by running

yum install [package_name]

Similarly, you can install several in one go

yum install [package1_name] [package2_name] [...]

In case you want to uninstall packages, follow this path

yum remove [package_name] 

Also, you can remove several

yum remove [package1_name] [package2_name] [...]

If you want to list all packages available for installation, upgrade, or already installed.

yum list

The on-screen output will be very long, but you can filter a bit with the `grep` command For example

yum list | grep [package_name]

Alternatively, you can use the `search` command

yum search [package_name]

If you want information about the package in question, you can do this with

yum info [package_name]

As we install and update packages, the YUM cache fills up and takes up disk space. It is, therefore, a good idea to clear it frequently to save space.

yum clean packages

YUM can also manage groups of packages that can help install certain common packages.

To list these available groups

yum grouplist

To install one, you have to run this command

yum groupinstall "[group_name]"

This will install all the packages in this group.

If you want to uninstall this group, you can run

yum groupremove "[group_name]"

To find out the information about this group, you have to run

yum groupinfo "[group_name]"

DNF Package manager for RHEL, CentOS and Fedora

On the opposite side to APT and YUM, we have DNF. In response to some concerns that YUM could not solve, DNF was born. For example, DNF has better memory utilization, improved dependency management, and the ability to run on Python 2 and Python 3.

So DNF is the package manager for distributions like RHEL, CentOS, and clones like Rocky Linux and Fedora. So it is arguably the second most popular in use.

One of the advantages DNF gives us is that it provides secure package management by allowing GPG signature verification on GPG signed packages. Therefore, DNF will not install any package that is not signed with the correct key for that repository.

As with APT, with DNF we can install, upgrade, uninstall packages quickly without worrying about the many dependencies they may have.

Using DNF package manager in Linux

Let’s change the order this time. If you want to list all packages you have to run the following command as root.

dnf list all

In case you want to get all the packages that are installed on the system

dnf list installed

But you can also list the packages that are not installed but are available in the repositories.

dnf list available

To search for a package, just add search criteria.

dnf list available "php*"

In this case, all packages related to PHP will be searched.

To find out some information about a particular package use the info subcommand.

dnf info [package_name]

Now that we have the package we want on our system, we can install it. In DNF the installation of packages is similar to APT. To install a package with DNF, just run

dnf install [package_name]

Similarly, you can install several packages in a single command.

dnf install [package1_name] [package2_name]

To remove a package just change install to remove.

dnf remove [package_name] [package2_name]

Then, if you want to upgrade the system completely, just run the following command

dnf update

Or update a single package:

dnf update [package_name]

A feature of DNF is that it can handle groups of packages within the official repositories of any of the distributions that implement it.

If you want to display the available package groups, run

dnf group list

It is also possible to get information about that particular group,

dnf group info "[group_name]"

Installing a group will install all packages in a group. To install a group of packages, use:

dnf group install "[package_group_name]"

If you have installed a package group, you also can uninstall it without problems.

dnf group remove "[package_group_name]"

Zypper is a SUSE package manager

SUSE is a very important company in the open-source world. This company develops SUSE Linux Enterprise dedicated to enterprise and server support. It has a community version called OpenSUSE, which is also a reference among the most common users.

As if that wasn’t enough, SUSE develops its technology to make its distributions as robust and modern as possible. Among those technologies, we have a package manager characterized by flexibility and ease of use such as Zypper.

Zypper is the package manager of OpenSUSE and therefore of SUSE Linux Enterprise. Like other package managers, it allows you to easily install, uninstall and search for packages. In addition to this, it allows you to manage repositories and set up a priority system where you can tell Zypper when to perform an update.

Using Zypper package manager

As you might expect, Zypper is available on OpenSUSE and SUSE as well as any derivative of these.

To refresh the repository database, the syntax is as follows

zypper refresh

If you want to search for a package within the official repositories, you have to run

zypper se [keyword]

With the above command, you can search for packages related to other packages. For example

zypper se php

This will show you all possible results related to PHP.

If you want to get the information about a particular package, just run

zypper info [package_name]

Now comes the good part, if you want to install a package just follow this formula

zypper in [package_name]

Just like APT and DNF you can install several packages at the same time

zypper in [package1_name] [package2_name] [...]

To uninstall a package simply use rm.

zypper rm [package_name]

You can also remove several packages at once.

This uninstalls the package but not its dependencies. In this case, run

zypper remove -clean-deps [package]

This removes packages along with all their dependencies not required by others; if one of them is used by another package, nothing will happen.

You can then upgrade the whole system by running the following command

zypper up

Then you can have the available packages upgraded.

Zypper also gives us the possibility to install only security patches for the system.

zypper patch

Also, you will be able to list which security patches the system needs.

zypper lp

Now we will manage the repositories with Zypper.

Working with repositories and patterns with Zypper

If you want to add a repository you just have to follow this syntax

zypper addrepo [Repo_URL] [alias]

The alias is important because it will be the repository identifier.

After you add a repository to the system, you can change the priority it has. The lower the number, the higher the priority will be. The default value is 99.

zypper mr -p [priority] [alias]

And you can remove it by following this

zypper removerepo [alias]

That’s how simple you can do it.

If you want to check all the active repositories on the system

zypper lr

Like DNF, Zypper allows you to manage groups of packages, which in OpenSUSE and SUSE are called pattern.

So to list all the available patterns you have to run

zypper se -t pattern

If you want to install a complete pattern with all the packages in it,

zypper in -t pattern [pattern_name]

And to remove it

zypper rm -t pattern [pattern_name]

For Arch Linux and derivatives we have pacman

Pacman is for many the best package manager in all of Linux. Because besides doing everything it is supposed to do, it does it with a speed and efficiency that APT, DNF, and Zypper would envy. Pacman is mainly used by Arch Linux, but it is also the package manager for derivatives like Manjaro and others. It is a veteran application because it was developed by Arch Linux creator Judd Vinet on 25 February 2002.

One of the reasons Pacman is so efficient is because it is built in the C language. This ensures that execution is practically at a low system level.

Like any package manager, the goal of pacman is to make it possible to easily manage packages, whether they are from the official repositories or the user’s builds.

So, let’s take a look at it.

Using Pacman on Linux

Like any package manager, you need to run it with root permission. So keep this in mind.

pacman -Sy

It is always advisable to do this frequently due to changes in the repositories.

To update the entire distribution, it is necessary to run this command

pacman -Su

This way, it will proceed to download all the updates that are available at the moment of running the command.

However, we can combine the previous commands into one. That is, refresh and synchronize with the remote repository and update the system at the same time.

pacman -Syu

In case you want to install a package, just run the following command

pacman -S [package]

Of course, you can specify several simultaneous packages.

pacman -S [package] [package2] [package3] [...]

To uninstall a package just use the -R option and specify it

pacman -R [package]

Similarly, you can specify multiple packages.

pacman -R [package] [package2] [package3] [...]

These commands only uninstall the package but not its dependencies. So it is advisable when uninstalling a package to tell pacman to do the same with the dependencies.

pacman -Rs [package]

Now if you want to remove the package’s configuration files as well, just add the n option

pacman -Rn [package]

If we combine the above commands then we can remove a package, its unneeded dependencies, and its configuration files.

pacman -Rsn [package]

More useful options on Pacman

To search for a package in the official repositories, just use the following option

pacman -Ss [package]

If you want even more information about the package you can use this command

pacman -Si [package]

But you can also check if a package is installed on the system with the Qs option.

pacman -Qs [package]

Another interesting option is to browse through each of the packages installed on the system. To do this

pacman -Q | less

You can further filter the list by excluding package dependencies.

pacman -Qe | less

Or find out which packages were installed from unofficial sources.

pacman -Qm

An important issue is hard disk space management, so you can clear the cache completely with this command

pacman -Scc

pacman performs very good package update, installation, and removal management so you can use it on an Arch Linux derivative system or on Arch Linux itself.

Conclusion

Throughout this post, we have explained the differences and uses of the different package managers in Linux. Each of them is efficient but they have different approaches.

I hope this post has helped you to understand them a bit more and let you get out of some trouble.

So, share this post and help us grow.

Ezoicreport this ad