How To Use DNF To Manage Software Packages On CentOS 7

June 10, 2019

Table of Contents

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

https://www.itweb.services/tutorials/linux-guides/hot-backups-with-percona-xtrabackup-on-the-one-click-wordpress-app”>this IT Web Services 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

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!