Sub topic 4
Package management: apt and dnf side by side
This chapter assumes you can use a Linux shell, have installed software with a package manager before, and know what a systemd service is. It compares how Debian and Ubuntu Server (the apt and dpkg tools) and Rocky Linux (the dnf and rpm tools) install, update, query, and remove software. The commands differ, but the model underneath is the same, and the differences that matter are in defaults and failure behavior.
Two layers on each side
Both families split package management into a low-level tool and a high-level tool.
- The low-level tool installs, removes, and inspects a single package file. It does not download anything and does not resolve dependencies. On Debian and Ubuntu this is
dpkg, which handles.debfiles. On Rocky it isrpm, which handles.rpmfiles. - The high-level tool reads repository metadata, works out dependencies, downloads packages, and calls the low-level tool. On Debian and Ubuntu this is
apt. On Rocky it isdnf.
On Rocky, yum still works, but it is a link to dnf. Use dnf in scripts and documentation.
The same task on both systems
The example below installs a web server and then shows where the package came from. The apt policy command lists the candidate version and the repository it comes from. The dnf info command prints the version, the repository in the From repo field, and a summary.
# Debian / Ubuntu
sudo apt update
sudo apt install nginx
apt policy nginx
# Rocky Linux
sudo dnf install nginx
dnf info nginxNote the first difference. On Debian and Ubuntu you run apt update first. This command downloads fresh package indexes. It does not upgrade anything, and the name misleads many newcomers. dnf refreshes its metadata on its own when the cached copy is older than metadata_expire, which defaults to 48 hours. You can force a refresh with sudo dnf makecache.
If you skip apt update on a new Debian or Ubuntu machine, apt install may fail with "Unable to locate package" or fetch an outdated version. Cloud images often ship with empty indexes.
Command equivalents
| Task | Debian / Ubuntu | Rocky Linux |
|---|---|---|
| Refresh metadata | `sudo apt update` | `sudo dnf makecache` (usually automatic) |
| Install | `sudo apt install pkg` | `sudo dnf install pkg` |
| Upgrade all packages | `sudo apt upgrade` | `sudo dnf upgrade` |
| Upgrade, allowing removals | `sudo apt full-upgrade` | `sudo dnf upgrade` (does this by default) |
| Remove, keep config | `sudo apt remove pkg` | `sudo dnf remove pkg` |
| Remove, delete config | `sudo apt purge pkg` | no equivalent |
| Remove unneeded dependencies | `sudo apt autoremove` | `sudo dnf autoremove` |
| Search by name or description | `apt search word` | `dnf search word` |
| Show package details | `apt show pkg` | `dnf info pkg` |
| List installed packages | `apt list --installed` or `dpkg -l` | `dnf list --installed` or `rpm -qa` |
| Which package owns a file | `dpkg -S /path/file` | `rpm -qf /path/file` |
| Which package could provide a file | `apt-file search file` (needs `apt-file`) | `dnf provides '*/file'` |
| List files in a package | `dpkg -L pkg` | `rpm -ql pkg` |
Two rows deserve more explanation.
upgrade versus full-upgrade. apt upgrade never removes an installed package and never installs a new one to satisfy a changed dependency. It holds such packages back. apt full-upgrade is allowed to do both. Kernel and library transitions sometimes need it. dnf upgrade has no such split and will remove or replace packages when the dependency solver requires it. Read the transaction summary before you confirm it.
purge. On Debian and Ubuntu, remove leaves configuration files in /etc, and purge deletes them. On Rocky, dnf remove follows the rpm rule: files marked as configuration that you edited are renamed with a .rpmsave suffix, and unedited ones are deleted.
Configuration files during upgrades
Both systems protect your local edits, but they do it differently.
- dpkg stops during an upgrade when a packaged config file changed upstream and you also edited it. It asks whether to keep your version or take the maintainer's. In unattended runs the default is to keep yours, and the new default is saved with a
.dpkg-distsuffix. - rpm never asks. It keeps your file and writes the new default beside it as
.rpmnew. If the package marks the file so that it must be replaced, it saves your copy as.rpmsave.
After a large upgrade on a Rocky host, search for leftovers with sudo find /etc -name '*.rpmnew' -o -name '*.rpmsave'. On Debian and Ubuntu, search for *.dpkg-dist and *.dpkg-old instead.
Services after installation
A common surprise is what happens to a service right after you install it.
- On Debian and Ubuntu, installing a package such as
nginxnormally enables the systemd unit and starts it immediately. A fresh install can start listening on a port before you have configured anything. - On Rocky, installing the package does not start or enable the service. You run
sudo systemctl enable --now nginxyourself.
Neither default is wrong, but they affect automation. A Debian-family provisioning script can end with a running service, while the same script on Rocky leaves the service stopped. Always state your intent explicitly with systemctl enable --now or systemctl disable --now.
Checking where a package came from
Before you install, check which repository will supply the package and which version you would get.
# Debian / Ubuntu: candidate version and every repository offering it
apt policy nginx
# Rocky Linux: all available versions and the repository for each
dnf list --showduplicates nginx
dnf repoquery --info nginxOn Ubuntu, apt policy shows pockets such as noble-updates and noble-security. A package may be available from several pockets, and apt installs the highest version unless pinned. On Rocky, the From repo line in dnf info tells you whether a package came from BaseOS, AppStream, EPEL, or a third-party repository. The next chapter covers repositories in detail.
Pinning, holding, and locking versions
Sometimes you must keep a package at a known version, for example a database server whose upgrade needs a planned maintenance window.
# Debian / Ubuntu
sudo apt-mark hold postgresql-16
apt-mark showhold
sudo apt-mark unhold postgresql-16
# Rocky Linux (needs the versionlock plugin)
sudo dnf install python3-dnf-plugin-versionlock
sudo dnf versionlock add postgresql-server
sudo dnf versionlock list
sudo dnf versionlock delete postgresql-serverOn Rocky you can also add exclude=postgresql* to a repository section or to /etc/dnf/dnf.conf. That blocks every version from updating, including security fixes, so use it sparingly.
Streams on Rocky
Rocky 8 and 9 ship an AppStream repository alongside BaseOS. Some software in AppStream is offered as modules with multiple streams, which are parallel major versions. For example, dnf module list postgresql can show several PostgreSQL versions, and sudo dnf module enable postgresql:16 selects one before you install. Switching streams later needs a reset and sometimes a package removal, so choose carefully.
Debian and Ubuntu have no direct equivalent. They generally offer one version of a package per release, which is why vendors publish their own repositories for newer versions. Debian and Ubuntu sometimes name versioned packages explicitly, such as postgresql-16 or php8.3-fpm.
Package names are not portable
The same software often has different names across families. Scripts that assume one name will fail on the other.
| Software | Debian / Ubuntu | Rocky Linux |
|---|---|---|
| Apache HTTP Server | `apache2` | `httpd` |
| OpenSSL headers for builds | `libssl-dev` | `openssl-devel` |
| C compiler toolchain | `build-essential` | `gcc make` or group `Development Tools` |
| DNS lookup tools | `dnsutils` or `bind9-dnsutils` | `bind-utils` |
| Cron daemon | `cron` | `cronie` |
Debian-family development packages end in -dev, and RPM-family ones end in -devel. When you cannot guess a name, search by file: apt-file search bin/dig or dnf provides '*/bin/dig'.
Automatic updates
Both families provide an unattended update tool, and their defaults differ.
- Ubuntu Server installs and enables
unattended-upgradesby default, configured to apply security updates. Debian includes the package in many installs, but whether it is enabled depends on how you installed it. - Rocky ships
dnf-automaticas an optional package. You install it and enable a timer such asdnf-automatic-install.timer. It does nothing until you do.
Automatic updates replace files on disk but do not restart running processes. After a library or kernel update, check whether a restart is needed:
# Ubuntu: this file exists when a reboot is pending
test -f /var/run/reboot-required && cat /var/run/reboot-required
# Debian / Ubuntu: list services still running old libraries
sudo apt install needrestart
sudo needrestart
# Rocky: needs dnf-utils
sudo dnf install dnf-utils
sudo needs-restarting -rHistory, rollback, and verification
Rocky keeps a transaction history that you can inspect and sometimes reverse.
sudo dnf history
sudo dnf history info 12
sudo dnf history undo 12Undoing a transaction works for installs and simple upgrades, but it can fail when the older package versions are no longer in any enabled repository. It is not a substitute for snapshots or backups. On Debian and Ubuntu, apt writes a log to /var/log/apt/history.log and dpkg writes to /var/log/dpkg.log. These record what happened but offer no undo. To go back, you install the older version explicitly with apt install pkg=version, if the repository still carries it.
For integrity checks, rpm -V pkg compares installed files against the package database and reports changed size, mode, or checksum. On Debian and Ubuntu, dpkg -V pkg does a similar check, though it is less commonly used. debsums can check against package checksums if you install it.
Locks and common errors
| Symptom | Likely cause | What to do | Column | Column |
|---|---|---|---|---|
| `Could not get lock /var/lib/dpkg/lock-frontend` | Another apt, dpkg, or `unattended-upgrades` process is running | Wait, or check with `ps aux \ | grep -E 'apt\ | dpkg'`. Do not delete lock files. |
| `dpkg was interrupted, you must manually run 'dpkg --configure -a'` | A previous install was cut off | Run `sudo dpkg --configure -a`, then `sudo apt -f install`. | ||
| `Unable to locate package` | Stale or missing index, or the package is in a repository you have not enabled | Run `sudo apt update`, then check the component (for example Ubuntu `universe`). | ||
| `Waiting for process with pid ... to release the lock` | Another dnf or PackageKit process is running | Wait. dnf retries by itself. | ||
| `Error: GPG check FAILED` | Repository key missing or changed | Import the correct key from the vendor, then retry. Do not disable `gpgcheck`. | ||
| `Problem: package ... requires ..., but none of the providers can be installed` | Conflicting repositories or stream selection | Run `dnf repolist`, check enabled streams with `dnf module list --enabled`, and remove the conflict. |
What this means for choosing a distribution
Package management itself rarely decides the choice, because both tools are mature and reliable. The practical differences are:
- The team's existing habits and scripts. Rewriting automation for a different family has a real cost.
- Package names and defaults, such as services starting at install time and unattended updates being enabled.
- How many versions of a package the distribution offers, and whether vendors publish repositories for it.
- Rollback options. dnf history gives more structure than apt logs, but neither replaces snapshots.
Exercises
Exercise
You run sudo apt install nginx on a freshly created Ubuntu cloud server and get "Unable to locate package nginx". Name the most likely cause and the command that fixes it. Then say what you would expect on Rocky Linux for the equivalent sudo dnf install nginx.
Show answer
The package index is empty or stale, which is common on new cloud images. Run sudo apt update and then retry the install. On Rocky, dnf refreshes its metadata automatically when the cache has expired, so the same mistake does not occur. If the install fails there, the cause is a missing repository or a network problem.
Exercise
A provisioning script installs nginx and then runs curl http://localhost. It works on Ubuntu but fails with "connection refused" on Rocky Linux. Why, and what single line should you add to make the script behave the same on both?
Show answer
On Debian and Ubuntu, installing the package starts and enables the service. On Rocky, the package installs the unit but leaves it stopped and disabled. Add sudo systemctl enable --now nginx after the install. It is also safe on Ubuntu, where it does nothing harmful.
Exercise
Which command tells you which package owns /usr/bin/dig on each family? Which command finds a package that would provide it if it is not installed?
Show answer
Installed file: dpkg -S /usr/bin/dig on Debian and Ubuntu, and rpm -qf /usr/bin/dig on Rocky. Not installed: apt-file search bin/dig (after installing apt-file and running sudo apt-file update) on Debian and Ubuntu, and dnf provides '*/bin/dig' on Rocky.