CentOS

CentOS 8 Package Management with dnf Package Manager

DNF is simply the next generation package manager (after YUM) for RPM based Linux distributions such as CentOS, RHEL, Fedora etc.  In this article, I am going to show you how to use the DNF package manager for CentOS 8 package management. So, let’s get started.

Updating Package Repository Cache:

You can update the DNF package repository cache with the following command:

$ sudo dnf makecache

DNF package repository cache should be updated.

Listing Enabled and Disabled Package Repositories:

You can list all (enabled and disabled) the package repositories available on your CentOS 8 machine with the following command:

$ sudo dnf repolist --all

As you can see, all the enabled and disabled package repositories are displayed. On the repo id column, you have the Repository Id which you can use with the DNF –repo option. In the status column, you can see which repository is enabled and how many packages that particular repository has.

The same way, you can list only the enabled repositories as follows:

$ sudo dnf repolist --enabled

The same way, you can list only the disabled repositories as follows:

$ sudo dnf repolist --disabled

Listing All Available Packages:

You can list all the packages in all the package repositories with the following command:

$ sudo dnf list --all

The list is very long.

As you can see, it’s about 6419 packages in total.

$ sudo dnf list | wc --lines

You can use grep or egrep to search for packages in the list as follows.

$ sudo dnf list | egrep searchTerm

Here, I searched for tree package as you can see in the screenshot below.

$ sudo dnf list | egrep ^tree

Listing All Installed Packages:

You can list only all the installed packages as follows:

$ sudo dnf list --installed

The list is very long as well.

Searching for Packages:

You can search for packages by their package name and summary as follows:

$ sudo dnf search "Programming Language"

The search result should display all the matched packages. You can choose what to install from here.

Searching for Packages in Specific Repositories:

You can search for packages by their package name as follows:

$ sudo dnf repoquery *kvm*

As you can see, all the packages that has kvm in the package name is listed.

You can also use –repo option to define which package repository to search as follows:

$ sudo dnf repoquery *centos* >--repo extras

$ sudo dnf repoquery *centos* --repo BaseOS

As you can see, two search query returned different results because they are from different package repository.

Searching for Packages that Provides Specific File:

Let’s say, you need a file or command but you don’t know what package to install. You can search by full or partial file path to find the package name as follows:

$ sudo dnf provides */ifconfig

As you can see, net-tools is the package that provides the /usr/sbin/ifconfig command.

You can find the package name that provides the tree command as follows:

$ sudo dnf provides */bin/tree

You can also search for packages that provide a specific library file as follows:

$ sudo dnf provides */libssl.so*

As you can see, the package name and which package provides which version of the library is listed.

Learning More about Packages:

You can learn more about a package as follows:

$ sudo dnf info tree

As you can see, the package version, summary, description, size, repository information and many more is listed.

Installing Packages:

You can install a package (let’s say, httpd) as follows:

$ sudo dnf install httpd

It will show you what dependencies it will install, the total number of packages it needs to download, the total download size, total size after installation etc.

To confirm the installation, press Y and then press <Enter>.

The package should be installed.

Reinstalling Packages:

You can reinstall a package as follows:

$ sudo dnf reinstall httpd

Now, press Y and then press <Enter> to confirm the reinstallation.

The package should be reinstalled.

Removing Packages:

You can remove a package as follows:

$ sudo dnf remove httpd

It will show you what package dependencies will be removed, how many packages will be removed and how much disk space will be freed.

To confirm the removal, press Y and then press <Enter>.

The package along will all its dependencies should be removed.

Doing a System Upgrade:

You can check for whether software updates are available with the following command:

$ sudo dnf check-update

If there are any software updates, it will be listed.

You can do a minimal software update with the following command:

$ sudo dnf upgrade-minimal

Minimal software update will only install absolutely required security patches.

At this time, I do not have any.

For full system update, run the following command:

$ sudo dnf upgrade

It will show you a summary of what packages will be upgraded, how many packages will be installed, how many will be upgraded, the total download size etc.

To confirm the system upgrade, press Y and then press <Enter>.

It will download and install the software updates.

Clear Caches:

You can clean DNF package caches with the following command:

$ sudo dnf clean all

All the available caches should be removed.

Remove Unnecessary Packages:

You can remove unnecessary packages if available to save disk space as follows:

$ sudo dnf autoremove

At this time, I have no unnecessary packages on my CentOS 8 machine.

So, that’s basically how you use DNF to manage packages on CentOS 8. It’s very similar to YUM. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.