Sub topic 4
Package management: apt and dnf side by side
Assume you are comfortable with a shell, sudo, systemd services, and the basic idea of software repositories. This chapter compares the daily package tasks used on Debian-family systems such as Ubuntu and Debian with those used on RHEL-compatible systems such as Rocky Linux.
The working model
A package manager installs software from repositories. A repository is a server or local source that provides signed package files and metadata. The package manager resolves dependencies, which are other packages required by the requested software.
Ubuntu and Debian use apt as the high-level package manager. It works with the lower-level dpkg package system and normally installs .deb packages.
Rocky Linux uses dnf as the high-level package manager. It works with the rpm package system and normally installs .rpm packages.
The command names differ, but the workflow is similar:
- Refresh repository metadata.
- Search for or inspect a package.
- Install, update, or remove the package.
- Check the installed result.
- Enable and start any service separately.
| Task | Ubuntu or Debian | Rocky Linux |
|---|---|---|
| Refresh metadata | `sudo apt update` | `sudo dnf makecache` |
| Install a package | `sudo apt install nginx` | `sudo dnf install nginx` |
| Inspect a package | `apt policy nginx` | `dnf info nginx` |
| Remove a package | `sudo apt remove nginx` | `sudo dnf remove nginx` |
| List installed packages | `dpkg -l` | `rpm -qa` |
A daily installation workflow
On an apt-based server, refresh metadata before installing software. This does not upgrade installed packages. It downloads current information about package versions and dependencies.
sudo apt update
apt policy nginx
sudo apt install nginx
nginx -v
sudo systemctl enable --now nginxOn a dnf-based server, installing a package normally refreshes metadata when needed. You can inspect the available package first.
dnf info nginx
sudo dnf install nginx
nginx -v
sudo systemctl enable --now nginxThe enable --now option both enables a service at boot and starts it immediately. Package installation alone does not always start a service, and it does not replace checking the service's configuration or listening ports.
Updating and removing software
For Debian or Ubuntu, use apt upgrade for routine upgrades. Use apt full-upgrade when dependency changes may require adding or removing packages. Review the proposed transaction before accepting it, especially on a production server.
sudo apt update
sudo apt upgrade
sudo apt autoremoveautoremove proposes packages that were installed as dependencies and are no longer needed. Review the list. A package that appears unused to the package manager may still be needed by a locally managed application.
For Rocky Linux, dnf upgrade updates installed packages and resolves dependencies.
sudo dnf upgrade
sudo dnf autoremoveBoth managers can remove software while leaving configuration files behind. On Debian-family systems, apt purge also removes package-managed configuration files:
sudo apt purge nginxDo not assume that removal deletes every application file. Files created after installation, such as application data, logs, and custom configuration, may remain.
Repositories and package provenance
Repository configuration controls where packages come from. Debian and Ubuntu commonly use files under /etc/apt/sources.list.d/. Rocky Linux commonly uses repository files under /etc/yum.repos.d/.
Package provenance matters. A vendor repository may provide a newer version than the distribution repository, but it also adds trust, update, and compatibility responsibilities. Prefer the distribution package when its version and support are sufficient. If you add a third-party repository, document its signing key, purpose, owner, and removal procedure.
Use package metadata to investigate a choice:
apt policy nginx
dnf info nginxThese commands help reveal the installed version, candidate version, repository, and package summary. Avoid mixing packages built for different distribution families. A .deb package is not interchangeable with an .rpm package.
A translation habit
Think in operations rather than command names. When moving between distributions, ask which command refreshes metadata, which command previews a transaction, and which command changes the system.
Exercise
On an Ubuntu server, what is the difference between sudo apt update and sudo apt upgrade, and what is the closest routine upgrade command on Rocky Linux?
Show answer
apt update refreshes repository metadata without changing installed packages. apt upgrade installs available package updates. The closest Rocky Linux command for routine updates is sudo dnf upgrade; dnf makecache only refreshes metadata.