Introduction

DNF (Dandified Yum) is the next-generation package manager for RPM-based distributions. It replaces YUM with improved dependency resolution, better performance, and a more modern codebase. While RHEL and CentOS 7 come with YUM as the default package manager, users may want to install DNF to leverage its advantages. This guide will walk you through the steps to install DNF on RHEL/CentOS 7.

Prerequisites

Before proceeding, ensure that you:

  • Have root or sudo privileges
  • Have a stable internet connection
  • Have RHEL 7 or CentOS 7 installed

Step 1: Update Your System

It’s always recommended to update your system before installing new software. Run the following command to ensure all existing packages are up to date:

sudo yum update -y

Step 2: Install the epel-release Repository

DNF is not included in the default RHEL/CentOS 7 repositories, so you need to enable the EPEL (Extra Packages for Enterprise Linux) repository:

sudo yum install -y epel-release

Once installed, update the repository metadata:

sudo yum update -y

Step 3: Install DNF

Now you can install DNF by running:

sudo yum install -y dnf

This command will install the necessary dependencies and set up DNF on your system.

Step 4: Verify the Installation

To confirm that DNF has been installed successfully, check its version:

dnf --version

If the installation was successful, you should see output similar to:

DNF version 2.x.x

Step 5: Make DNF the Default Package Manager (Optional)

Since YUM is still the default package manager in RHEL/CentOS 7, you can replace it with DNF for package management tasks. If you wish to use DNF instead of YUM by default, you can create symbolic links:

sudo mv /usr/bin/yum /usr/bin/yum.bak
sudo ln -s /usr/bin/dnf /usr/bin/yum

This ensures that when you run yum commands, they are redirected to dnf.

Step 6: Using DNF

You can now use DNF as you would use YUM. Here are some common package management commands:

Install a package:

sudo dnf install package-name

Remove a package:

sudo dnf remove package-name

Update all packages:

sudo dnf update -y

Search for a package:

dnf search package-name

Clean up unused packages:

sudo dnf autoremove -y

Conclusion

Installing DNF on RHEL/CentOS 7 provides an enhanced package management experience with improved performance and better dependency handling. By following this guide, you can easily install and start using DNF on your system. If you plan to upgrade to a newer version of RHEL or CentOS, you’ll already be familiar with DNF, as it is the default package manager in RHEL 8 and later.