Use DNF To Manage Software Packages On CentOS 7

Updated on November 21, 2023
Use DNF To Manage Software Packages On CentOS 7 header image

Since Fedora 22, DNF (Dandified Yum) has replaced Yum to become the default software package manager of the Fedora distribution. Considering the demonstration effect of Fedora, it is just a matter of time before DNF becomes fashionable on other RPM-based distributions.

Compared with Yum, DNF:

  • achieves faster dependency resolving speed with less memory usage,
  • provides specific and solid Python API documentation,
  • runs in both Python 2 and Python 3 environments, and
  • has similar synopsis and usage.

Besides working on all of the RPM-based distributions, DNF can also co-exist with its predecessor, Yum. So you can already pilot DNF on CentOS or other RPM-based distributions without concerns.

Prerequisites

All of the instructions in this tutorial are geared to the needs of a sudo user on a Vultr CentOS 7 server instance. You need to log in as a sudo user to test the following commands. For instructions on how to create such a user, see this Vultr tutorial.

Install DNF on CentOS

You need to setup the EPEL Yum repo before you can install DNF.

sudo yum install epel-release
sudo yum install dnf

Note:

On CentOS 6, you will get a "No package dnf available" notice after you have run the commands above, because the DNF program has not been added into the EPEL 6.x Yum repo. You would need to build DNF from source.

DNF's basic usages and examples

Synopsis of the dnf command:

[sudo] dnf [options] <command> [<arguments>...]

Now, I will show you some examples of how to use DNF:

Upgrade all packages

sudo dnf upgrade

or

sudo dnf update

Unlike in Yum, DNF's "update" sub command is deprecated, now it becomes the alias of "upgrade".

Search for the package you need

dnf list <package-name>

You can use wildcards to match more packages:

dnf list php* 

Search for an installed package

dnf list --installed <package-name>

Display repo list

dnf repolist

Install a single package

sudo dnf install <package-name>

Install multiple packages

sudo dnf install <package1-name> <package2-name> <package3-name>

Reinstall a package

sudo dnf reinstall <package-name>

Upgrade a single package

sudo dnf upgrade <package-name>

Uninstall a package

sudo dnf remove <package-name>

Uninstall all dependency packages which are no longer required

sudo dnf autoremove

Clean all temporary files

sudo dnf clean all

Consult dnf man page

You can consult the dnf man page to learn more about dnf sub commands and usages:

dnf --help

or

dnf -h

or

man dnf