DNF is a package manager for CentOS, Fedora and RHEL operating systems. It is used to install, update, remove and manage packages on the RPM-based operating system. It is a next generation version of the older YUM command. Compared to YUM, DNF provides improved performance, low memory usage, speed, dependency resolution and more.
In this guide, we will show you how to use the DNF command to manage packages on CentOS 8.
# Requirements
- A server running CentOS 8 Linux operating system.
- A root password is set up on your server.
# Install and Remove a Package with DNF
DNF provides an easier way to install any package to your system. You will need to specify install followed by package-name to install the package to your system.
For example, to install the Nginx server package, run the following command:
dnf install nginx -y
If you want to reinstall any package, run the following command:
dnf reinstall nginx -y
If you want to download any package without installing it to your system, run the following command:
dnf download net-tools -y
This will download net-tools-2.0-0.52.20160912git.el8.x86_64.rpm file to your system:
Last metadata expiration check: 0:00:34 ago on Sunday 30 May 2021 06:00:45 AM EDT.
net-tools-2.0-0.52.20160912git.el8.x86_64.rpm 2.7 MB/s | 322 kB 00:00
To remove a package from your system, run the following command:
dnf remove nginx -y
Or
dnf erase nginx -y
To remove Orphan packages that are not used by any applications, run the following command:
dnf autoremove
To remove all cached packages, run the following command:
dnf clean all
# Update a Package with DNF
If you want to check your system for the update, run the following command:
dnf check-update
You should see the list of all packages that needs update:
NetworkManager.x86_64 1:1.26.0-12.el8_3 BaseOS
NetworkManager-libnm.x86_64 1:1.26.0-12.el8_3 BaseOS
NetworkManager-team.x86_64 1:1.26.0-12.el8_3 BaseOS
NetworkManager-tui.x86_64 1:1.26.0-12.el8_3 BaseOS
PackageKit.x86_64 1.1.12-6.el8 AppStream
PackageKit-glib.x86_64 1.1.12-6.el8 AppStream
adcli.x86_64 0.8.2-7.el8 BaseOS
authselect.x86_64 1.2.1-2.el8 BaseOS
authselect-compat.x86_64 1.2.1-2.el8 AppStream
authselect-libs.x86_64 1.2.1-2.el8 BaseOS
bash.x86_64 4.4.19-12.el8 BaseOS
bind-export-libs.x86_64 32:9.11.20-5.el8_3.1 BaseOS
To update a single package, run the following command:
dnf update httpd -y
If you want to upgrade all packages, run the following command:
dnf upgrade -y
If you want to synchronize all packages to the latest stable release, run the following command:
dnf distro-sync
# Search a Package with DNF
If you want to find any package in the repository, you can use the search followed by package-name.
For example, to search a package named vsftpd, run the following command:
dnf search vsftpd
You should see the following output:
Last metadata expiration check: 0:03:52 ago on Sunday 30 May 2021 06:00:45 AM EDT.
======================================================== Name Exactly Matched: vsftpd
=========================================================
vsftpd.x86_64 : Very Secure Ftp Daemon
If you want to list all available packages in your system, run the following command:
dnf list available | less
If you want to list only installed packages, run the following command:
dnf list installed
Output:
Installed Packages
NetworkManager.x86_64 1:1.22.8-4.el8 @BaseOS
NetworkManager-libnm.x86_64 1:1.22.8-4.el8 @BaseOS
NetworkManager-team.x86_64 1:1.22.8-4.el8 @BaseOS
NetworkManager-tui.x86_64 1:1.22.8-4.el8 @BaseOS
PackageKit.x86_64 1.1.12-4.el8 @AppStream
PackageKit-glib.x86_64 1.1.12-4.el8 @AppStream
abattis-cantarell-fonts.noarch 0.0.25-4.el8 @AppStream
# View Package Information
If you want to see the detail information about any package, run the following command:
dnf info nginx
You should see the following output:
Last metadata expiration check: 0:05:35 ago on Sunday 30 May 2021 06:00:45 AM EDT.
Available Packages
Name : nginx
Epoch : 1
Version : 1.14.1
Release : 9.module_el8.0.0+184+e34fea82
Architecture : x86_64
Size : 570 k
Source : nginx-1.14.1-9.module_el8.0.0+184+e34fea82.src.rpm
Repository : AppStream
Summary : A high performance web server and reverse proxy server
URL : http://nginx.org/
License : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
: IMAP protocols, with a strong focus on high concurrency, performance and low
: memory usage.
# Check DNF History
If you want to list all DNF command that you have executed on the system, run the following command:
dnf history
You should see the following output with transactions id:
ID | Command line | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
12 | install net-tools | 2021-05-30 06:11 | Upgrade | 1
11 | install httpd | 2021-05-30 06:03 | Install | 9
10 | erase nginx -y | 2021-05-30 06:02 | Removed | 32
9 | reinstall nginx -y | 2021-05-30 06:01 | R | 2
8 | install nginx -y | 2021-05-30 06:00 | Install | 32
7 | autoremove -y | 2020-06-19 15:37 | Removed | 3
6 | update | 2020-06-19 15:27 | E, I, U | 285 EE
5 | update | 2020-02-24 13:24 | I, U | 312 EE
4 | update | 2019-12-10 12:32 | I, U | 41 EE
3 | install -y acpid nano ma | 2019-09-26 12:09 | Install | 1
2 | remove -y smartmontools | 2019-09-26 12:08 | Removed | 1
1 | | 2019-09-26 10:34 | Install | 543 EE
You can now use this transactions id to get the detailed information of that transaction:
dnf history info 12
Output:
Transaction ID : 12
Begin time : Sunday 30 May 2021 06:11:12 AM EDT
Begin rpmdb : 566:986ac3e49ad7a20420896a98a4a980bde118f8d5
End time : Sunday 30 May 2021 06:11:13 AM EDT (1 seconds)
End rpmdb : 566:e94a7335e89061eb578b51f9b8f050dcb0eb4571
User : root <root>
Return-Code : Success
Releasever : 8
Command Line : install net-tools
Packages Altered:
Upgrade net-tools-2.0-0.52.20160912git.el8.x86_64 @BaseOS
Upgraded net-tools-2.0-0.51.20160912git.el8.x86_64 @@System
# List and Install Group Packages
To list all group packages, run the following command:
dnf grouplist
Output:
Last metadata expiration check: 0:01:56 ago on Sunday 30 May 2021 06:10:03 AM EDT.
Available Environment Groups:
Server with GUI
Server
Workstation
Virtualization Host
Custom Operating System
Installed Environment Groups:
Minimal Install
Available Groups:
Container Management
.NET Core Development
RPM Development Tools
Development Tools
Graphical Administration Tools
Headless Management
Legacy UNIX Compatibility
Network Servers
Scientific Support
Security Tools
Smart Card Support
System Tools
From the above list, install a specific group package, run the following command:
dnf groupinstall "Security Tools"
To remove a group package, run the following command;
dnf groupremove "Security Tools"
# Conclusion
In the above guide, you learned how to manage packages with DNF on CentOS 8 operating system. I hope this guide will help you to manage packages on all RPM-based operating systems.