Sub topic 2
How apt and dnf relate to dpkg and rpm
Assume you are comfortable with a Linux shell, sudo, package repositories, and systemd status commands. This chapter focuses on the layers beneath the commands you use to install and update software.
Two package-management layers
A Linux package system usually has two important layers:
- A low-level package tool installs one package file, records its files, and maintains a local package database.
- A high-level package manager finds packages in repositories, resolves dependencies, downloads packages, and calls the low-level tool.
Debian and Ubuntu use .deb packages. Their low-level tool is dpkg, and their common high-level tool is apt.
RHEL-family systems use .rpm packages. Their low-level tool is rpm, and their common high-level tool is dnf.
| Distribution family | Package file | Low-level tool | High-level tool |
|---|---|---|---|
| Debian and Ubuntu | `.deb` | `dpkg` | `apt` |
| RHEL, Fedora, Rocky, AlmaLinux | `.rpm` | `rpm` | `dnf` |
The high-level tool does not replace the low-level tool. It coordinates it.
What happens during an installation
When you run sudo apt install nginx, apt reads repository metadata, selects a suitable version, calculates dependencies, downloads the required .deb files, and invokes dpkg to unpack and configure them.
When you run sudo dnf install nginx, dnf performs the equivalent work with repository metadata and .rpm files, then invokes rpm to install and configure them.
The low-level tool records facts such as:
- Which package versions are installed.
- Which files belong to each package.
- Which package scripts have run.
- Which dependencies a package declares.
The high-level tool adds system-wide decisions. It chooses versions, handles dependencies across repositories, and usually verifies repository signatures before installation.
flowchart LR
A[Administrator] --> B[apt or dnf]
B --> C[Repository metadata]
B --> D[Dependency resolution]
B --> E[Downloaded package]
E --> F[dpkg or rpm]
F --> G[Local package database]
F --> H[Installed files and configuration]Use the right layer
Use apt or dnf for normal installations, updates, and removals. These commands understand repositories and can select all required dependencies.
Use dpkg or rpm for inspection and for specialized low-level operations. For example, you might query which package owns a file or inspect the contents of a local package file.
Installing a downloaded package directly with dpkg -i or rpm -Uvh can be useful during troubleshooting, but these commands do not provide the same repository-wide dependency resolution. A direct installation may leave a package unpacked but not configured because another dependency is missing.
> callout warning > Do not treat dpkg and rpm as replacements for apt and dnf. A low-level command can change the local package database without choosing or downloading everything the system needs. >
Common errors
A frequent error is mixing package families. A .deb package cannot normally be installed with rpm, and an .rpm package cannot normally be installed with dpkg.
Another error is assuming that a successful command means an application is ready. Package installation can run configuration scripts, enable files, or create a service, but it does not always start that service. Check the service separately when appropriate.
You can inspect installed packages without changing them:
dpkg -l nginx
rpm -q nginxThe first command queries Debian's package database. The second queries RPM's database on a RHEL-family system.
Check your understanding
Exercise
Which tool should normally resolve dependencies and obtain packages from configured repositories: dpkg/rpm or apt/dnf?
Show answer
apt or dnf. They are the high-level tools that resolve dependencies and obtain packages, while dpkg and rpm perform low-level package installation and database operations.