>_ Operating systems & Linux

Linux package managers: apt, dnf and pacman compared

How software is installed on Linux: packages, repositories and dependencies, equivalent apt, dnf and pacman commands, Flatpak, Snap and rules to stay safe.

On Windows you download an installer from a website; on Linux, in most cases, you ask the package manager for the program. It is one of the areas where Linux anticipated by years what we now call an «app store»: a single tool installs, updates and removes all the software on the system, from the kernel to the music player, checking where it comes from.

Packages, repositories and dependencies

A package is an archive containing a program's files, information about where to copy them and the list of dependencies, that is the libraries and other packages it needs. A repository is an online archive of packages maintained by the distribution and digitally signed: the manager checks the signature before installing, so a package tampered with along the way is rejected.

When you install a program, the manager works out which dependencies are missing and installs them as well. When you update, it updates the whole system in one go, libraries included. That is why on Linux there is no program quietly updating itself in a corner of the screen while another stays vulnerable.

The main families

  • Debian, Ubuntu, Linux Mint use .deb packages and the apt tool.
  • Fedora, Red Hat Enterprise Linux, AlmaLinux, Rocky Linux use .rpm packages and the dnf tool.
  • Arch Linux and derivatives such as Manjaro use pacman.
  • openSUSE uses .rpm packages with the zypper tool.

Equivalent commands

Operation apt dnf pacman
refresh the package list apt update automatic pacman -Sy
upgrade the system apt upgrade dnf upgrade pacman -Syu
search apt search name dnf search name pacman -Ss name
install apt install name dnf install name pacman -S name
remove apt remove name dnf remove name pacman -R name
information apt show name dnf info name pacman -Si name
which package owns this file dpkg -S /path dnf provides /path pacman -Qo /path

Every operation that changes the system requires sudo. With apt, update only downloads the refreshed list of available packages; it is upgrade that actually installs the new versions. Forgetting update leads to installing old versions or to file-not-found errors.

On Arch there is an important rule: never run pacman -Sy name to install a single package without upgrading the rest. This so-called partial upgrade can leave incompatible libraries behind; the correct form is pacman -Syu name.

Cleaning up and orphaned packages

When you remove a program, its dependencies may stay installed without serving any purpose. apt autoremove, dnf autoremove and, on Arch, pacman -Rns $(pacman -Qdtq) remove them. Before confirming it is worth reading the list: sometimes it includes a package you use directly but that had been installed as a dependency. In that case simply mark it as manually installed, with apt-mark manual name on Debian and Ubuntu.

The cache of downloaded packages also takes space: apt clean empties it, paccache on Arch keeps only the latest versions.

Extra repositories: with judgement

Sometimes a program is not in the official repositories or appears there in an old version. The solutions are additional repositories: PPAs on Ubuntu, COPR on Fedora, the AUR on Arch, or repositories run directly by the software's vendor. They work, but each is one more source of trust: whoever runs it can install anything on your system with every update. Practical rules:

  1. Add only repositories from people you know, such as the program's vendor.
  2. Keep few of them and remove those you no longer use.
  3. On the AUR read the PKGBUILD file before building: it is a script and it runs on your machine.
  4. Avoid installing .deb or .rpm files downloaded from unknown websites.

Flatpak, Snap and AppImage

Alongside traditional packages there are formats that bundle the program and its libraries in a single container, independent of the distribution.

  • Flatpak, with the Flathub catalogue, is widespread for desktop applications and runs them in an isolated environment with configurable permissions.
  • Snap, developed by Canonical, is built into Ubuntu and is also used for services and command-line tools.
  • AppImage is a single executable file to download and run, with no installation and no automatic updates.

The advantage is having recent versions on a stable distribution; the cost is more disk space and, sometimes, less polished integration with the rest of the desktop. A good division of labour: system and tools from the package manager, recent desktop applications from Flatpak.

Do not mix sources

The mistake that most often breaks a Linux system is installing the same software from different sources, for example a library from the repository and a newer hand-compiled version on top of the same directory. The package manager no longer knows what is on the disk, and the next update overwrites files or leaves them inconsistent. If you must install something by hand, use /usr/local or /opt, which the manager does not touch.

In short

  • The package manager installs, updates and removes all software, verifying its signature.
  • apt, dnf and pacman do the same things with different syntax; on Arch avoid partial upgrades.
  • autoremove deletes orphaned dependencies, but read the list before confirming.
  • Every extra repository is one more source of trust: add few, and reliable ones.
  • Flatpak is handy for desktop applications; do not mix packages and manual installs in the same directories.
MM
Marco Marzaduri

Marco Marzaduri works in cybersecurity, digital forensics and web development. With degrees in computer science and psychology, he combines technical analysis with an understanding of the human factor.

Read also