Understanding Linux Package Management: APT vs. YUM vs. DNF
A practical comparison of APT, YUM, and DNF for installing, updating, removing, and troubleshooting Linux packages.
Understanding Linux Package Management: APT vs. YUM vs. DNF
If you move between Ubuntu, Debian, Fedora, Rocky Linux, AlmaLinux, or RHEL, package management is one of the first places where muscle memory breaks. The job is the same everywhere: install software, apply security updates, remove what you no longer need, and keep dependencies consistent. The commands and file locations are different enough that copying the wrong runbook can waste time or damage a host.
APT, YUM, and DNF are not competing tools you normally choose between on one machine. They belong to different distribution families. APT is the normal high-level tool on Debian-based systems. YUM was the long-time high-level tool on older Red Hat-based systems. DNF is the modern replacement on current Fedora, RHEL 8 and newer, CentOS Stream, Rocky Linux, and AlmaLinux.
What is a Package Manager?
At its heart, a package manager is a collection of software tools that automate the process of installing, upgrading, configuring, and removing software packages from an operating system. Instead of compiling software from source code or manually managing dependencies, a package manager interacts with software repositories to fetch pre-compiled binaries and handle all necessary prerequisites automatically.
Key functions of a package manager include:
- Dependency Resolution: Automatically identifies and installs all required libraries and other software packages that a particular application needs to function.
- Software Repositories: Manages connections to remote servers (repositories) where packages are stored, ensuring access to a wide range of software.
- System Upgrades: Facilitates the update of individual packages or the entire operating system, ensuring security patches and new features are applied.
- Package Integrity: Verifies the authenticity and integrity of packages using digital signatures to prevent tampering.
- Clean Removal: Ensures that when software is uninstalled, all its associated files and dependencies are removed cleanly, avoiding system clutter.
Linux distributions typically use one of two main package formats: .deb for Debian-based systems and .rpm for Red Hat-based systems. APT manages .deb packages, while YUM and DNF manage .rpm packages.
APT (Advanced Package Tool)
APT is the command-line utility for managing .deb packages primarily found on Debian and its derivatives, such as Ubuntu, Linux Mint, Pop!_OS, and many others. It's renowned for its robust dependency resolution and a vast ecosystem of software.
Core Concepts
dpkg: Whileaptis the high-level tool,dpkgis the underlying low-level tool that actually installs, removes, and manages individual.debpackages. APT acts as a front-end todpkg, handling repositories and dependencies.sources.list: The/etc/apt/sources.listfile (and files in/etc/apt/sources.list.d/) defines the locations of software repositories that APT uses to find packages. These can be official repositories, third-party PPAs (Personal Package Archives), or local sources.- Package Structure: Packages are distributed as
.debfiles, which are essentially archives containing the compiled software, configuration files, and metadata.
Common APT Commands
Historically, apt-get was the primary command, but the apt command (introduced around Debian 8 / Ubuntu 16.04) offers a more user-friendly interface by combining the most common features of apt-get and apt-cache.
| Task | apt Command |
Description |
|---|---|---|
| Update package lists | sudo apt update |
Refreshes the list of available packages and their versions from repositories. |
| Upgrade installed packages | sudo apt upgrade |
Upgrades all installed packages to their newest versions. Does not remove packages. |
| Full system upgrade | sudo apt full-upgrade |
Upgrades all installed packages, removing old ones if necessary to resolve dependencies. |
| Install a package | sudo apt install <package_name> |
Installs a specified package and its dependencies. |
| Remove a package | sudo apt remove <package_name> |
Removes a package but keeps its configuration files. |
| Purge a package | sudo apt purge <package_name> |
Removes a package and its configuration files. |
| Search for a package | apt search <keyword> |
Searches for packages matching a keyword. |
| Show package details | apt show <package_name> |
Displays detailed information about a package. |
| Clean up old packages | sudo apt autoremove |
Removes automatically installed dependency packages that are no longer needed. |
Examples
# Update package lists
sudo apt update
# Install the 'nginx' web server
sudo apt install nginx
# Upgrade all installed packages
sudo apt upgrade
# Remove 'nginx' and its configuration files
sudo apt purge nginx
Advantages of APT
- Reliable dependency handling: APT is good at explaining what it plans to install, upgrade, keep back, or remove before it changes the system.
- Large repository ecosystem: Debian and Ubuntu repositories cover a wide range of server and desktop software.
- Predictable server behavior: Stable Debian and Ubuntu LTS releases usually prioritize tested package versions over the newest upstream release.
Disadvantages of APT
- Newer Software Versions: Sometimes, packages in official repositories might not be the absolute latest versions due to the focus on stability and thorough testing.
YUM (Yellowdog Updater, Modified)
YUM was the primary package manager for Red Hat Enterprise Linux (RHEL) and its derivatives like CentOS, Fedora (until recently), and Scientific Linux. It operates on .rpm (Red Hat Package Manager) packages.
Core Concepts
rpm: Similar todpkg,rpmis the low-level package management tool for.rpmfiles. YUM acts as a higher-level front-end..repofiles: Repository configurations are typically defined in.repofiles located in/etc/yum.repos.d/. These files specify the base URL, GPG keys, and other metadata for each repository.- Package Structure: Software is distributed as
.rpmfiles, containing binaries, libraries, and metadata.
Common YUM Commands
| Task | yum Command |
Description |
|---|---|---|
| Check for updates | sudo yum check-update |
Checks for available updates without installing them. |
| Update all packages | sudo yum update |
Updates all installed packages. |
| Install a package | sudo yum install <package_name> |
Installs a specified package and its dependencies. |
| Remove a package | sudo yum remove <package_name> |
Removes a package. |
| Search for a package | yum search <keyword> |
Searches for packages matching a keyword. |
| Show package details | yum info <package_name> |
Displays detailed information about a package. |
| Clean cached files | sudo yum clean all |
Cleans up cached repository metadata and packages. |
Examples
# Check for available updates
sudo yum check-update
# Install the 'httpd' (Apache) web server
sudo yum install httpd
# Update all installed packages
sudo yum update
# Remove 'httpd'
sudo yum remove httpd
Advantages of YUM
- Mature enterprise behavior: YUM is still common on older RHEL and CentOS systems, so you will see it in legacy runbooks.
- Transaction history:
yum historycan show previous installs, updates, and removals. In some cases you can undo or roll back a transaction, but you should test this carefully because configuration files, service state, and external data are not magically restored.
Disadvantages of YUM
- Performance: Can sometimes be slower compared to modern package managers like DNF, especially with large repositories or complex dependency trees.
- Being Replaced: In newer RHEL-based systems (RHEL 8+), DNF has replaced YUM as the default package manager, though
yumoften still works as an alias fordnf.
DNF (Dandified YUM)
DNF is the next-generation package manager for Red Hat-based distributions, serving as the successor to YUM. It's the default on Fedora (since version 18), RHEL 8+, CentOS Stream, AlmaLinux, and Rocky Linux. DNF addresses many of YUM's shortcomings, offering improved performance and dependency resolution.
Core Concepts
libsolv: DNF useslibsolvfor dependency resolution, which is highly optimized and provides significantly better performance than YUM's older solver.- Modularity: A key feature in RHEL 8+ and Fedora, modularity allows for different versions or streams of a software package (e.g., Python 3.6 vs. Python 3.8) to be available simultaneously, and users can choose which one to install.
- Compatibility: DNF maintains a command-line interface that is largely compatible with YUM, making the transition easier for users.
Common DNF Commands
Many DNF commands are identical or very similar to YUM commands.
| Task | dnf Command |
Description |
|---|---|---|
| Check for updates | sudo dnf check-update |
Checks for available updates without installing them. |
| Update all packages | sudo dnf update |
Updates all installed packages. |
| Install a package | sudo dnf install <package_name> |
Installs a specified package and its dependencies. |
| Remove a package | sudo dnf remove <package_name> |
Removes a package. |
| Search for a package | dnf search <keyword> |
Searches for packages matching a keyword. |
| Show package details | dnf info <package_name> |
Displays detailed information about a package. |
| Clean cached files | sudo dnf clean all |
Cleans up cached repository metadata and packages. |
| List available modules | dnf module list |
Lists available software module streams. |
| Enable a module | sudo dnf module enable <module> |
Enables a specific module stream. |
Examples
# Check for available updates
sudo dnf check-update
# Install the 'mariadb-server' database
sudo dnf install mariadb-server
# Update all installed packages
sudo dnf update
# List available Node.js module streams
dnf module list nodejs
# Enable Node.js 16 module stream (if available)
sudo dnf module enable nodejs:16
# Remove 'mariadb-server'
sudo dnf remove mariadb-server
Advantages of DNF
- Improved dependency solving: DNF uses
libsolv, which generally handles complex dependency choices faster and more clearly than older YUM behavior. - Cleaner output and APIs: DNF is easier to script around than older YUM in many administrative workflows.
- Modularity: Provides flexibility for installing different versions of software within the same system.
- Modern Design: Built with a clear API for extensions and cleaner code.
Disadvantages of DNF
- Newer Technology: While stable, some features, especially related to modularity, might require a slightly steeper learning curve for new users.
Key Differences and Use Cases
The fundamental distinction between APT and YUM/DNF lies in the distribution family they serve and the package format they handle.
| Feature | APT (Debian/Ubuntu) | YUM/DNF (RHEL/Fedora) |
|---|---|---|
| Package Format | .deb (Debian Package) |
.rpm (Red Hat Package) |
| Underlying Tool | dpkg |
rpm |
| Config Files | /etc/apt/sources.list |
/etc/yum.repos.d/*.repo |
| Primary Distros | Debian, Ubuntu, Mint, Pop!_OS | RHEL, Fedora, CentOS, AlmaLinux, Rocky Linux |
| Dependency Solver | Internal (robust, well-tested) | YUM: Internal (slower); DNF: libsolv (faster, modern) |
| Evolution | apt-get -> apt |
yum -> dnf |
| Modularity | Not directly built-in (PPAs for flexibility) | DNF offers module streams for multiple versions |
- APT is ideal for users and administrators who prioritize rock-solid stability, extensive community support, and a vast software repository. It's the go-to for Debian-based systems, which are popular for both servers and desktops.
- YUM served its purpose well in enterprise environments for years, providing a stable and proven method for managing software. While still present as an alias, its direct usage is being phased out.
- DNF is the modern standard for Red Hat-based systems. It's the choice for those running contemporary RHEL, Fedora, or their derivatives, offering performance, advanced dependency resolution, and features like modularity, making it excellent for development and production environments requiring specific software versions.
Best Practices for Package Management
Regardless of which package manager you're using, adhering to best practices ensures a healthy and secure system:
- Regular Updates: Periodically run
sudo apt update && sudo apt upgradeorsudo dnf updateto apply security patches and bug fixes. - Understand Before Installing: Always check what a package does and its reputation before installing, especially from third-party repositories.
- Verify Repository Sources: Ensure that any added repositories are trustworthy to prevent installing malicious or unstable software.
- Clean Up: Use
sudo apt autoremoveorsudo dnf autoremoveto remove orphaned dependencies and free up disk space. - Review
apt showordnf info: Before installing, use these commands to get details about the package, including its dependencies and size. - Backup Critical Systems: Before performing major upgrades (e.g.,
apt full-upgradeor distribution upgrades), ensure you have a backup of critical data and configurations.
Troubleshooting Package Manager Problems
Most package manager failures are not mysterious once you separate them into three buckets: repository metadata, dependency conflicts, and local package database state.
If APT says it cannot find a package, start with sudo apt update. APT does not query every remote repository fresh for every install. It uses local metadata. If the package was recently added, or if the machine has not refreshed its lists in a while, the install can fail even though the repository is correct. If apt update itself fails, read the repository line in the error. A stale PPA, expired signing key, broken mirror, or unsupported distribution codename is often the real issue.
On DNF or YUM systems, the equivalent first move is usually:
sudo dnf makecache
sudo dnf repolist
On older systems:
sudo yum makecache
sudo yum repolist
repolist is useful because it confirms whether the repository is enabled at all. A package may be available from EPEL, CodeReady Builder, PowerTools, CRB, or a vendor repository, but not from the base OS repositories. In that case the fix is not to download a random RPM from the web. The cleaner fix is to enable the correct repository and let the package manager handle dependencies.
Dependency conflicts need more care. If APT proposes removing a large part of the system, stop and read the transaction. The same applies to dnf remove. Removing a package can remove services that depend on it. On servers, I like to copy the proposed transaction into the incident notes before accepting it. That gives you a record of what changed if a service breaks afterward.
For interrupted installs, use the native repair command before trying manual cleanup:
# Debian/Ubuntu
sudo dpkg --configure -a
sudo apt -f install
# Fedora/RHEL-family
sudo dnf check
sudo dnf history
Manual deletion under /var/lib/dpkg, /var/lib/rpm, /var/cache/apt, or /var/cache/dnf should be a last resort. Those directories are package manager state, not ordinary clutter.
A Practical Translation Cheat Sheet
When you are following documentation written for a different Linux family, translate the intent, not only the command.
| Task | Debian/Ubuntu | Fedora/RHEL-family |
|---|---|---|
| Refresh repository metadata | sudo apt update |
sudo dnf makecache |
| Upgrade installed packages | sudo apt upgrade |
sudo dnf upgrade or sudo dnf update |
| Install a package | sudo apt install nginx |
sudo dnf install nginx |
| Remove a package | sudo apt remove nginx |
sudo dnf remove nginx |
| Remove package and config | sudo apt purge nginx |
No exact equivalent; package scripts may leave config/data |
| Search packages | apt search nginx |
dnf search nginx |
| Show package info | apt show nginx |
dnf info nginx |
| List installed packages | apt list --installed |
dnf list installed |
| See package files | dpkg -L nginx |
rpm -ql nginx |
| Find owning package for a file | dpkg -S /path/file |
rpm -qf /path/file |
That last pair is underrated. If you find a strange binary or config file on a host, dpkg -S or rpm -qf tells you which package owns it. If no package owns it, the file may have been created by an application, a deployment script, an administrator, or an attacker. That does not prove anything by itself, but it gives you a better next question.
The safest way to think about package management is simple: stay inside the tool your distribution expects, read transactions before accepting them, and treat third-party repositories as production dependencies. Once you know where repository files live and how to inspect package ownership, APT, YUM, and DNF feel much less like different worlds.