Install DNF on RHEL/CentOS 7: A Complete Technical Guide
DNF (Dandified YUM) is the next-generation package manager for RPM-based Linux distributions, designed as a full replacement for YUM. It delivers faster dependency resolution through the `libsolv` library, lower memory consumption, and a stable Python API. While RHEL/CentOS 7 ships with YUM by default, DNF is fully installable via the EPEL repository and can run in parallel with — or as a transparent replacement for — YUM on the same system.
This guide walks through the complete installation process, explains the architectural differences between YUM and DNF, covers real-world edge cases, and gives you a production-ready command reference.
Why DNF Outperforms YUM on RHEL/CentOS 7
Before touching the terminal, understanding *why* the upgrade matters helps you make an informed decision — especially on a long-running VPS Hosting environment where package management reliability is critical.
Core Architectural Differences
YUM relies on a Python-based dependency resolver that has well-documented performance issues with large dependency trees. DNF replaces that resolver with `libsolv`, a SAT-solver-based dependency resolution engine originally developed by SUSE. The practical consequences are significant:
- Dependency resolution speed: DNF resolves complex dependency chains in a fraction of the time YUM requires, particularly noticeable when resolving conflicts in large package sets.
- Memory footprint: YUM loads entire repository metadata into memory. DNF uses lazy loading and caches more aggressively, reducing peak RAM usage.
- API stability: YUM's Python API changed unpredictably between minor versions. DNF exposes a documented, versioned Python API that plugin authors can rely on.
- Plugin architecture: DNF uses a clean hook-based plugin system. YUM plugins often interfere with each other due to loose coupling.
- Transaction history: DNF maintains a richer transaction history database, making rollbacks and audits more precise.
YUM vs. DNF: Feature Comparison
| Feature | YUM | DNF |
|---|
| — | — | — |
|---|
| Dependency resolver | Python-based (internal) | `libsolv` SAT solver |
|---|
| Memory usage | Higher (full metadata load) | Lower (lazy loading + aggressive cache) |
|---|
| Python API | Unstable across versions | Stable, versioned API |
|---|
| Plugin system | Loosely coupled, conflict-prone | Hook-based, isolated |
|---|
| Transaction rollback | Limited | Full history with rollback support |
|---|
| Parallel downloads | No | Yes (via `librepo`) |
|---|
| Weak dependencies | Not supported | Supported (`Recommends`, `Suggests`) |
|---|
| Module streams | Not supported | Supported (DNF 4+) |
|---|
| Maintenance status | End-of-life | Actively maintained |
|---|
| Default on RHEL/CentOS | 7 and earlier | 8 and later |
|---|
Prerequisites
Before proceeding, confirm the following:
- A running instance of RHEL 7 or CentOS 7 (bare metal, VM, or a cloud VPS).
- Root or sudo access — all installation commands require elevated privileges.
- Active internet connectivity — the EPEL repository must be reachable.
- At least 500 MB of free disk space for DNF, its dependencies, and repository metadata cache.
If you are running a minimal CentOS 7 installation on a Dedicated Server, verify that `curl` and `wget` are available, as they are occasionally absent in stripped-down images.
Step 1: Update Existing System Packages
Synchronizing your package database before installing new software prevents version conflicts and ensures that the EPEL release package installs cleanly against your current RPM database state.
“`bash
sudo yum update -y
“`
What this does: Downloads and applies all available updates for currently installed packages, refreshes repository metadata, and rebuilds the RPM transaction lock. On a production system, schedule this during a maintenance window — kernel updates require a reboot to take effect.
Edge case: If `yum update` fails with a `Multilib version problems` error, run `sudo yum update –setopt=protected_multilib=false -y` as a one-time workaround, then investigate the conflicting packages before proceeding.
Step 2: Enable the EPEL Repository
DNF is not available in the default CentOS/RHEL 7 base repositories. The Extra Packages for Enterprise Linux (EPEL) repository, maintained by the Fedora project, provides it.
“`bash
sudo yum install epel-release -y
“`
Verify the repository is active:
“`bash
yum repolist | grep epel
“`
Expected output should show `epel/x86_64` with a non-zero package count (typically 13,000+). If the repository appears disabled, force-enable it:
“`bash
sudo yum-config-manager –enable epel
“`
Security note: EPEL packages are built and signed by the Fedora infrastructure team. The `epel-release` package installs the GPG key automatically. You can verify the key fingerprint against the official Fedora key server before trusting packages from this repository — a step worth taking on hardened production systems.
Behind a proxy or firewall? If your server cannot reach the Fedora mirrors directly, configure `/etc/yum.conf` with your proxy settings:
“`ini
proxy=http://your-proxy-server:port
proxy_username=user
proxy_password=pass
“`
Step 3: Install DNF
With EPEL active, install DNF and its core dependencies in a single command:
“`bash
sudo yum install dnf -y
“`
This pulls in `dnf`, `dnf-data`, `python-dnf`, `libcomps`, `librepo`, and `libsolv` as automatic dependencies. The total download size is typically between 3–8 MB depending on what is already installed.
What gets installed:
- `dnf` — the main binary and command-line interface
- `libsolv` — the SAT-based dependency resolver
- `librepo` — the parallel download library
- `libcomps` — comps XML parser for package groups
- `python-dnf` — Python bindings and the DNF core library
Step 4: Verify the Installation
Confirm that DNF is operational and check its version:
“`bash
dnf –version
“`
A successful installation produces output similar to:
“`
4.0.9.2
Installed: dnf-0:4.0.9.2-1.el7.noarch at …
Built : CentOS BuildSystem <http://bugs.centos.org> at …
“`
Run a deeper sanity check by listing available repositories as seen by DNF:
“`bash
dnf repolist
“`
The output should mirror what `yum repolist` shows, confirming that DNF has correctly inherited your existing repository configuration from `/etc/yum.repos.d/`.
Important: DNF on CentOS 7 reads the same repository `.repo` files as YUM. No repository migration is required. Both tools share `/etc/yum.repos.d/` and `/var/cache/` (in separate subdirectories).
Step 5: Core DNF Command Reference
DNF is intentionally command-compatible with YUM. The following table covers the operations you will use most frequently:
| Task | DNF Command |
|---|
| — | — |
|---|
| Update all packages | `sudo dnf update -y` |
|---|
| Install a package | `sudo dnf install <package> -y` |
|---|
| Remove a package | `sudo dnf remove <package> -y` |
|---|
| Search for a package | `dnf search <keyword>` |
|---|
| Get package info | `dnf info <package>` |
|---|
| List installed packages | `dnf list installed` |
|---|
| List available updates | `dnf check-update` |
|---|
| Clean cached metadata | `sudo dnf clean all` |
|---|
| View transaction history | `dnf history` |
|---|
| Rollback a transaction | `sudo dnf history undo <id>` |
|---|
| Install a package group | `sudo dnf groupinstall "<group>"` |
|---|
| Enable a repository | `sudo dnf config-manager –enable <repo>` |
|---|
DNF Transaction History and Rollback
This is one of DNF's most operationally valuable features and one that YUM handles poorly. Every install, update, or removal is recorded in `/var/lib/dnf/history/`. To inspect recent transactions:
“`bash
dnf history list
“`
To see exactly what changed in a specific transaction:
“`bash
dnf history info <transaction-id>
“`
To undo a transaction (for example, rolling back a bad update):
“`bash
sudo dnf history undo <transaction-id>
“`
This capability is particularly useful on a VPS with cPanel where a package update might conflict with control panel dependencies.
DNF Configuration File
DNF's global configuration lives at `/etc/dnf/dnf.conf`. Key tuning parameters for production use:
“`ini
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False
“`
- `installonly_limit=3` — keeps only the last 3 kernel versions, preventing `/boot` from filling up.
- `clean_requirements_on_remove=True` — removes orphaned dependencies automatically on package removal.
- `best=True` — always installs the latest available version, raising an error instead of silently downgrading.
Step 6: Configuring DNF as the Default Package Manager
On RHEL/CentOS 7, YUM remains the system default. You have two options for making DNF your primary interface.
Option A: Shell Alias (User-Level, Non-Destructive)
Add the following to `~/.bashrc` (for the current user) or `/etc/bashrc` (system-wide):
“`bash
alias yum='dnf'
“`
Apply immediately:
“`bash
source ~/.bashrc
“`
Limitation: This alias only applies to interactive shell sessions. Scripts that invoke `yum` directly via their absolute path (`/usr/bin/yum`) or that run under different users (e.g., cron jobs, systemd units) are unaffected.
Option B: Symbolic Link (System-Level)
For a more thorough replacement, create a symbolic link that redirects the `yum` binary to `dnf`:
“`bash
sudo mv /usr/bin/yum /usr/bin/yum.bak
sudo ln -s /usr/bin/dnf /usr/bin/yum
“`
Critical warning: This approach affects all users and all scripts system-wide. Test thoroughly in a non-production environment first. Some system scripts and third-party tools (including certain cPanel/WHM components) explicitly call `/usr/bin/yum` and may behave unexpectedly if the binary is replaced. Always back up the original binary as shown above.
Option C: DNF as YUM Plugin (Recommended for Servers)
The cleanest approach for production servers is to leave YUM intact and simply use `dnf` explicitly in your own workflows and automation scripts. This avoids any risk of breaking system tooling while giving you full access to DNF's capabilities.
Practical Pitfalls and Edge Cases
These are issues that surface in real deployments and are rarely covered in basic tutorials.
GPG key conflicts: If you install packages from multiple third-party repositories, DNF's stricter GPG enforcement (when `gpgcheck=1`) may reject packages that YUM previously accepted silently. Always import repository GPG keys explicitly with `sudo rpm –import <key-url>`.
Plugin incompatibility: Some YUM plugins (e.g., `yum-plugin-fastestmirror`) have no direct DNF equivalent or behave differently. DNF has its own `fastestmirror` plugin (`dnf-plugin-fastestmirror`), but it is not enabled by default. Install it with `sudo dnf install python3-dnf-plugin-fastestmirror`.
Cache location divergence: YUM caches metadata in `/var/cache/yum/`. DNF uses `/var/cache/dnf/`. If disk space is tight, both caches can coexist and consume significant space. Run `sudo dnf clean all` and `sudo yum clean all` independently to reclaim space.
RHEL subscription management: On registered RHEL 7 systems (as opposed to CentOS), the `subscription-manager` plugin integrates with YUM. DNF on RHEL 7 may not fully honor subscription-gated repositories without additional configuration. Verify with `subscription-manager repos –list-enabled` after switching.
Python version sensitivity: DNF on CentOS 7 uses Python 2 bindings (`python-dnf`). If you have upgraded to Python 3 on your system, ensure you are not inadvertently breaking the `python-dnf` dependency chain. DNF 4+ on RHEL 8+ uses Python 3 natively.
Planning Your Migration Path Beyond CentOS 7
CentOS 7 reached end-of-life on June 30, 2024. Installing DNF is a useful operational improvement, but it does not change the underlying security posture of an EOL distribution. If you are still running CentOS 7 workloads, a migration plan to AlmaLinux 8/9, Rocky Linux 8/9, or RHEL 8/9 should be on your roadmap. All of these distributions use DNF natively, making the familiarity you build now directly transferable.
For teams running multiple services on aging infrastructure, VPS Control Panels can significantly simplify the management of parallel environments during a migration window.
If your workloads include web hosting stacks, migrating to a modern distribution also enables you to take full advantage of SSL Certificates automation via Certbot and ACME, which has significantly better support on RHEL 8+ and its derivatives.
Quick-Reference Decision Matrix
Use this checklist before and after the installation to confirm a clean, production-safe setup:
- [ ] `yum update -y` completed without errors before installing EPEL
- [ ] EPEL repository verified active via `yum repolist | grep epel`
- [ ] `dnf –version` returns a valid version string
- [ ] `dnf repolist` output matches `yum repolist` output
- [ ] `/etc/dnf/dnf.conf` reviewed and tuned for your environment
- [ ] `installonly_limit` set to prevent `/boot` partition overflow
- [ ] Decision made on alias vs. symlink vs. coexistence strategy
- [ ] YUM binary backed up if symlink approach is used
- [ ] Cron jobs and automation scripts audited for hardcoded `yum` paths
- [ ] CentOS 7 EOL migration timeline documented
FAQ
Can DNF and YUM coexist on the same CentOS 7 system without conflicts?
Yes. Both tools read from `/etc/yum.repos.d/` and maintain separate cache directories. They share the RPM database (`/var/lib/rpm`), so a transaction completed by one is immediately visible to the other. Running both simultaneously (e.g., two concurrent installs) will cause an RPM lock conflict, but sequential use is fully safe.
Will installing DNF on CentOS 7 break existing YUM plugins?
No. DNF installs as an independent binary and does not modify the YUM installation. Your existing YUM plugins remain intact. However, DNF does not load YUM plugins — if you rely on specific YUM plugins, you need to find and install their DNF equivalents separately.
Does DNF on CentOS 7 support DNF modules (module streams)?
No. DNF module streams are a feature introduced in DNF 4 and RHEL/CentOS 8. The version of DNF available via EPEL for CentOS 7 is DNF 4.x but module stream support requires the AppStream repository infrastructure, which does not exist on CentOS 7.
Why does `dnf update` sometimes produce different results than `yum update` on the same system?
DNF's `libsolv` resolver applies stricter dependency logic and may resolve version selections differently than YUM's internal resolver. In most cases the outcome is identical, but in environments with complex or conflicting dependencies, DNF may select different package versions or refuse transactions that YUM would have silently allowed. This is a feature, not a bug — DNF's behavior is more predictable and auditable.
Is it safe to use DNF on a CentOS 7 server that hosts production web applications?
Yes, with the caveat that you use the coexistence approach (leave YUM intact, use DNF explicitly) rather than replacing the YUM binary. Verify that any control panel software or deployment automation on your server does not have hardcoded assumptions about YUM behavior before switching your primary workflow to DNF.
