DNF stands for Dandified YUM, it is a completely updated version of YUM Package Manager. It was originally introduced on Fedora 18, and has now become the default package manager on Fedora 22, RHEL, and CentOS-8 to handle the RPM package management. DNF improves the deficiencies of YUM, including poor performance, high memory usage, and slowness for dependency resolution. The current and stable version of DNF is 4.2.7.
In this article, how to use dnf commands in Fedora, CentOS, and RHEL with many sub-commands, it will help to all the Newbies and System Admins. All the following examples of DNF commands are tested on RHEL and CentOS 8.
Recommended reading: 15 Useful YUM commands for Beginners in Linux
Prerequisites :
Operating System : Fedora / CentOS / RHEL User account : root user or user account with sudo privileges Recommended to run all the administrative command as with sudo privilege instead of root.
Difficulties in setting up sudo users? --> Click here to find the steps <--.
Global Syntax of dnf command in Linux:
dnf [options] [command] [package ...]
The following table provides an overview of the options of 'dnf' command in Fedora, RHEL / CentOS 8.
1. How do I check if any packages are available for updates?
$ sudo dnf check-update
Output: anaconda-core.x86_64 29.19.2.17-1.el8 AppStream anaconda-gui.x86_64 29.19.2.17-1.el8 AppStream anaconda-tui.x86_64 29.19.2.17-1.el8 AppStream anaconda-user-help.noarch 1:8.2.3-1.el8 AppStream anaconda-widgets.x86_64 29.19.2.17-1.el8 AppStream appstream-data.noarch 8-20191129.el8 AppStream audit.x86_64 3.0-0.17.20191104git1c2f876.el8 BaseOS audit-libs.x86_64 3.0-0.17.20191104git1c2f876.el8 BaseOS augeas-libs.x86_64 1.12.0-5.el8 BaseOS baobab.x86_64 3.28.0-4.el8 AppStream
Note:
2. How to install a new package?
$ sudo dnf install vsftpd
Output: Dependencies resolved. ======================================================================================= Package Architecture Version Repository Size ======================================================================================= Installing: vsftpd x86_64 3.0.3-31.el8 AppStream 180 k Transaction Summary ======================================================================================== Install 1 Package Total download size: 180 k Installed size: 343 k Is this ok [y/N]: y
Note:
3. How to update a specific package?
$ sudo dnf update passwd -y
Output: Dependencies resolved. ======================================================================================= Package Architecture Version Repository Size ======================================================================================= Upgrading: passwd x86_64 0.80-3.el8 BaseOS 115 k Transaction Summary ======================================================================================== Upgrade 1 Package
Note:
$sudo dnf update -y
4. How to exclude a particular package from being updated?
Note:
$ sudo dnf check-update
Output:
exiv2-libs.x86_64 0.27.2-5.el8 AppStream
file.x86_64 5.33-13.el8 BaseOS
file-libs.x86_64 5.33-13.el8 BaseOS
firefox.x86_64 68.10.0-1.el8_2 AppStream
firewalld.noarch 0.8.0-4.el8 BaseOS
firewalld-filesystem.noarch 0.8.0-4.el8 BaseOS
flatpak.x86_64 1.6.2-2.el8 AppStream
flatpak-libs.x86_64 1.6.2-2.el8 AppStream
$ sudo dnf update -x firewalld* --nobest
Output: Dependencies resolved. ================================================================================================================ Package ArchVersion Repo Size ================================================================================================================ Upgrading: exiv2 x86_640.27.2-5.el8 AppStream 1.0 M exiv2-libs x86_640.27.2-5.el8 AppStream 851 k firefox x86_6468.10.0-1.el8_2 AppStream 94 M flatpak x86_641.6.2-2.el8 AppStream 1.5 M flatpak-libs x86_641.6.2-2.el8 AppStream 413 k fprintd x86_641.90.0-0.20191121gitf022902.el8 AppStream 103 k Skipping packages with conflicts: (add '--best --allowerasing' to the command line to force their upgrade): python3-firewall noarch 0.8.0-4.el8 BaseOS 389 k Transaction Summary ====================================================================================================================================================== Install 18 Packages Upgrade 572 Packages Skip 1 Package Total download size: 631 M Is this ok [y/N]: y
Note:
$ sudo dnf update -x package_name1* -x package_name2* --nobest
5. How about installing only security updates?
Note:
$ sudo dnf updateinfo list --security
$ sudo dnf upgrade --security
6. How to uninstall a specific package?
$ sudo dnf remove vsftpd
Output: Dependencies resolved. ============================================================================================ Package Architecture Version Repository Size ============================================================================================ Removing: vsftpd x86_64 3.0.3-31.el8 @AppStream 343 k Transaction Summary ============================================================================================= Remove 1 Package Freed space: 343 k Is this ok [y/N]: y
Note:
7. How to get the list of all the combined packages?
$ sudo dnf list all
Output: (Installed Packages) exiv2-libs.x86_64 0.26-10.el8 @AppStream expat.x86_64 2.2.5-3.el8 @anaconda file.x86_64 5.33-8.el8 @anaconda file-libs.x86_64 5.33-8.el8 @anaconda file-roller.x86_64 3.28.1-2.el8 @AppStream (Available Packages) brotli-devel.x86_64 1.0.6-1.el8 AppStream bsdtar.x86_64 3.3.2-8.el8_1 BaseOS bubblewrap.x86_64 0.4.0-1.el8 BaseOS buildah.x86_64 1.11.6-7.module_el8.2.0+305+5e198a41 AppStream buildah-tests.x86_64 1.11.6-7.module_el8.2.0+305+5e198a41 AppStream
Note:
$ sudo dnf list installed "sssd-?*" --nobest OR $ sudo dnf list installed | grep sssd-
Output: Installed Packages sssd-ad.x86_64 2.2.0-19.el8 @anaconda sssd-client.x86_64 2.2.0-19.el8 @anaconda sssd-common.x86_64 2.2.0-19.el8 @anaconda sssd-common-pac.x86_64 2.2.0-19.el8 @anaconda sssd-ipa.x86_64 2.2.0-19.el8 @anaconda sssd-kcm.x86_64 2.2.0-19.el8 @anaconda sssd-krb5.x86_64 2.2.0-19.el8 @anaconda sssd-krb5-common.x86_64 2.2.0-19.el8 @anaconda sssd-ldap.x86_64 2.2.0-19.el8 @anaconda sssd-nfs-idmap.x86_64 2.2.0-19.el8 @anaconda sssd-proxy.x86_64 2.2.0-19.el8 @anaconda
8. How do I reinstall the package?
$ sudo dnf reinstall vsftpd
Output:
Dependencies resolved.
========================================================================================================
Package Architecture Version Repository Size
========================================================================================================
Reinstalling:
vsftpd x86_64 3.0.3-31.el8 AppStream 180 k
Transaction Summary
========================================================================================================
Total download size: 180 k
Installed size: 343 k
Is this ok [y/N]: y
Note:
9. How do you view detailed information about a particular package?
$ sudo dnf info vsftpd
Output: Installed Packages Name : vsftpd Version : 3.0.3 Release : 31.el8 Architecture : x86_64 Size : 343 k Source : vsftpd-3.0.3-31.el8.src.rpm Repository : @System From repo : AppStream Summary : Very Secure Ftp Daemon URL : https://security.appspot.com/vsftpd.html License : GPLv2 with exceptions Description : vsftpd is a Very Secure FTP daemon. It was written completely from : scratch.
Note:
10. How to download an .rpm package file?
Note:
$ sudo dnf download samba
Output:
[sudo] password for linuxteck:
Last metadata expiration check: 21:36:25 ago on Monday 13 July 2020 07:14:36 PM IST.
samba-4.11.2-13.el8.x86_64.rpm
Note:
$ sudo dnf download samba --resolve
Output: (1/26): samba-libs-4.11.2-13.el8.x86_64.rpm 68 kB/s | 170 kB 00:02 (2/26): libipa_hbac-2.2.3-20.el8.x86_64.rpm 76 kB/s | 103 kB 00:01 (3/26): samba-common-tools-4.11.2-13.el8.x86_64.rpm 109 kB/s | 472 kB 00:04 (4/26): libldb-2.0.7-3.el8.x86_64.rpm 255 kB/s | 180 kB 00:00 (5/26): libsmbclient-4.11.2-13.el8.x86_64.rpm 228 kB/s | 146 kB 00:00 (6/26): libtalloc-2.2.0-7.el8.x86_64.rpm 238 kB/s | 49 kB 00:00 (7/26): samba-4.11.2-13.el8.x86_64.rpm 147 kB/s | 766 kB 00:05 (8/26): libsss_idmap-2.2.3-20.el8.x86_64.rpm 168 kB/s | 107 kB 00:00 (9/26): libtdb-1.4.2-2.el8.x86_64.rpm 196 kB/s | 59 kB 00:00 (10/26): libtevent-0.10.0-2.el8.x86_64.rpm 84 kB/s | 49 kB 00:00 (11/26): libwbclient-4.11.2-13.el8.x86_64.rpm 144 kB/s | 117 kB 00:00 (12/26): python3-sssdconfig-2.2.3-20.el8.noarch.rpm 149 kB/s | 120 kB 00:00 (13/26): samba-common-libs-4.11.2-13.el8.x86_64.rpm 241 kB/s | 173 kB 00:00 (14/26): samba-common-4.11.2-13.el8.noarch.rpm 202 kB/s | 212 kB 00:01 (15/26): sssd-2.2.3-20.el8.x86_64.rpm 194 kB/s | 94 kB 00:00 (16/26): sssd-ad-2.2.3-20.el8.x86_64.rpm 234 kB/s | 235 kB 00:01 (17/26): sssd-client-2.2.3-20.el8.x86_64.rpm 224 kB/s | 171 kB 00:00 (18/26): sssd-common-pac-2.2.3-20.el8.x86_64.rpm 201 kB/s | 165 kB 00:00 (19/26): sssd-ipa-2.2.3-20.el8.x86_64.rpm 223 kB/s | 328 kB 00:01 (20/26): sssd-kcm-2.2.3-20.el8.x86_64.rpm 96 kB/s | 218 kB 00:02 (21/26): sssd-common-2.2.3-20.el8.x86_64.rpm 228 kB/s | 1.5 MB 00:06 (22/26): sssd-krb5-common-2.2.3-20.el8.x86_64.rpm 316 kB/s | 174 kB 00:00 (23/26): sssd-krb5-2.2.3-20.el8.x86_64.rpm 50 kB/s | 129 kB 00:02 (24/26): sssd-ldap-2.2.3-20.el8.x86_64.rpm 250 kB/s | 208 kB 00:00 (25/26): sssd-proxy-2.2.3-20.el8.x86_64.rpm 92 kB/s | 129 kB 00:01 (26/26): samba-client-libs-4.11.2-13.el8.x86_64.rpm 311 kB/s | 5.1 MB 00:16
Note:
$ ls
Output:
libipa_hbac-2.2.3-20.el8.x86_64.rpm samba-4.11.2-13.el8.x86_64.rpm sssd-common-2.2.3-20.el8.x86_64.rpm
libldb-2.0.7-3.el8.x86_64.rpm samba-client-libs-4.11.2-13.el8.x86_64.rpm sssd-common-pac-2.2.3-20.el8.x86_64.rpm
libsmbclient-4.11.2-13.el8.x86_64.rpm samba-common-4.11.2-13.el8.noarch.rpm sssd-ipa-2.2.3-20.el8.x86_64.rpm
libsss_idmap-2.2.3-20.el8.x86_64.rpm samba-common-libs-4.11.2-13.el8.x86_64.rpm sssd-kcm-2.2.3-20.el8.x86_64.rpm
libtalloc-2.2.0-7.el8.x86_64.rpm samba-common-tools-4.11.2-13.el8.x86_64.rpm sssd-krb5-2.2.3-20.el8.x86_64.rpm
libtdb-1.4.2-2.el8.x86_64.rpm samba-libs-4.11.2-13.el8.x86_64.rpm sssd-krb5-common-2.2.3-20.el8.x86_64.rpm
libtevent-0.10.0-2.el8.x86_64.rpm sssd-2.2.3-20.el8.x86_64.rpm sssd-ldap-2.2.3-20.el8.x86_64.rpm
libwbclient-4.11.2-13.el8.x86_64.rpm sssd-ad-2.2.3-20.el8.x86_64.rpm sssd-proxy-2.2.3-20.el8.x86_64.rpm
python3-sssdconfig-2.2.3-20.el8.noarch.rpm sssd-client-2.2.3-20.el8.x86_64.rpm
11. How to install a .rpm package file using dnf?
$ sudo dnf localinstall samba-4.11.2-13.el8.x86_64.rpm
Output: Dependencies resolved. ============================================================================================== Package Architecture Version Repository ============================================================================================== Installing: samba x86_64 4.11.2-13.el8 @commandline Upgrading: samba-common noarch 4.11.2-13.el8 BaseOS samba-common-libs x86_64 4.11.2-13.el8 BaseOS sssd x86_64 2.2.3-20.el8 BaseOS sssd-ad x86_64 2.2.3-20.el8 BaseOS sssd-proxy x86_64 2.2.3-20.el8 BaseOS Installing dependencies: samba-common-tools x86_64 4.11.2-13.el8 BaseOS samba-libs x86_64 4.11.2-13.el8 BaseOS Transaction Summary =============================================================================================== Install 3 Packages Upgrade 5 Packages Total size: 3 M Total download size: 2 M Is this ok [y/N]: y
Note:
12. How to clear the cache details from the dnf cache directory?
$ sudo dnf clean all
Output: [sudo] password for linuxteck: 22 files removed
Note:
13. How to install a package group?
Note:
$ sudo dnf groups summary
Output:
[sudo] password for linuxteck:
CentOS-8 - AppStream 106 kB/s | 5.8 MB 00:55
CentOS-8 - Base 104 kB/s | 2.2 MB 00:21
CentOS-8 - Extras 6.1 kB/s | 6.7 kB 00:01
Installed Groups: 2
Available Groups: 10
Note:
$ sudo dnf grouplist
Output:
[sudo] password for linuxteck:
CentOS-8 - AppStream 229 B/s | 4.3 kB 00:19
CentOS-8 - Base 562 B/s | 3.9 kB 00:07
CentOS-8 - Extras 272 B/s | 1.5 kB 00:05
Available Environment Groups:
Server
Minimal Install
Workstation
Virtualization Host
Custom Operating System
Installed Environment Groups:
Server with GUI
Installed Groups:
Container Management
Headless Management
Available Groups:
.NET Core Development
RPM Development Tools
Development Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Network Servers
Scientific Support
Security Tools
Smart Card Support
System Tools
Note:
$ sudo dnf groupinfo "Server"
Output: Environment Group: Server Description: An integrated, easy-to-manage server. no group 'dns-server' from environment 'server-product-environment' Mandatory Groups: Container Management Core Hardware Support Headless Management Server product core Standard Optional Groups: Basic Web Server Debugging Tools FTP Server File and Storage Server GNOME Guest Agents Hardware Monitoring Utilities Infiniband Support Mail Server Network File System Client Network Servers Performance Tools Remote Management for Linux Virtualization Hypervisor Windows File Server
Note:
$ sudo dnf groupinfo "Basic Web Server"
Output: Group: Basic Web Server Description: These tools allow you to run a Web server on the system. Mandatory Packages: httpd Default Packages: httpd-manual mod_fcgid mod_ssl Optional Packages: libmemcached memcached mod_auth_gssapi mod_security mod_security-mlogc mod_security_crs
Note:
$ sudo dnf groupinstall "Basic Web Server"
Output: Dependencies resolved. ========================================================================================================================= Package Architecture Version Repository Size ========================================================================================================================== Installing group/module packages: httpd x86_64 2.4.37-21.module_el8.2.0+382+15b0afa8 AppStream 1.7 M httpd-manual noarch 2.4.37-21.module_el8.2.0+382+15b0afa8 AppStream 2.4 M mod_fcgid x86_64 2.3.9-16.el8 AppStream 86 k mod_ssl x86_64 1:2.4.37-21.module_el8.2.0+382+15b0afa8 AppStream 132 k Installing dependencies: apr x86_64 1.6.3-9.el8 AppStream 125 k apr-util x86_64 1.6.1-6.el8 AppStream 105 k httpd-filesystem noarch 2.4.37-21.module_el8.2.0+382+15b0afa8 AppStream 36 k httpd-tools x86_64 2.4.37-21.module_el8.2.0+382+15b0afa8 AppStream 103 k mod_http2 x86_64 1.11.3-3.module_el8.2.0+307+4d18d695 AppStream 157 k centos-logos-httpd noarch 80.5-2.el8 BaseOS 24 k Installing weak dependencies: apr-util-bdb x86_64 1.6.1-6.el8 AppStream 25 k apr-util-openssl x86_64 1.6.1-6.el8 AppStream 27 k Enabling module streams: httpd 2.4 Installing Groups: Basic Web Server Transaction Summary ====================================================================================================================================================== Install 12 Packages Total download size: 4.8 M Installed size: 14 M Is this ok [y/N]: y
Note:
14. How to search package names from Repository?
$ sudo dnf search samba
Output:
==================================================================================
samba.x86_64 : Server and Client software to interoperate with Windows machines
============================================== Name & Summary Matched: samba ==================
samba-libs.i686 : Samba libraries
samba-libs.x86_64 : Samba libraries
samba-winbind.x86_64 : Samba winbind
samba-client.x86_64 : Samba client programs
python3-samba.i686 : Samba Python3 libraries
python3-samba.x86_64 : Samba Python3 libraries
samba-client-libs.i686 : Samba client libraries
samba-client-libs.x86_64 : Samba client libraries
python3-samba-test.x86_64 : Samba Python libraries
samba-winbind-clients.x86_64 : Samba winbind clients
samba-winbind-modules.i686 : Samba winbind modules
samba-winbind-modules.x86_64 : Samba winbind modules
samba-winbind-krb5-locator.x86_64 : Samba winbind krb5 locator
samba-test.x86_64 : Testing tools for Samba servers and clients
samba-common-tools.x86_64 : Tools for Samba servers and clients
ipa-client-samba.x86_64 : Tools to configure Samba on IPA client
samba-common.noarch : Files used by both Samba servers and clients
pcp-pmda-samba.x86_64 : Performance Co-Pilot (PCP) metrics for Samba
samba-krb5-printing.x86_64 : Samba CUPS backend for printing with Kerberos
samba-common-libs.x86_64 : Libraries used by both Samba servers and clients
samba-test-libs.x86_64 : Libraries need by the testing tools for Samba servers and clients
================================================================ Name Matched: samba ============
samba-pidl.noarch : Perl IDL compiler
=============================================================== Summary Matched: samba ==========
ctdb.x86_64 : A Clustered Database based on Samba's Trivial Database (TDB)
Note:
15. How to find the package name and file path?
Note:
$ sudo dnf provides */useradd
Output: shadow-utils-2:4.6-8.el8.x86_64 : Utilities for managing accounts and shadow : password files Repo : @System Matched from: Filename : /etc/default/useradd Filename : /usr/sbin/useradd shadow-utils-2:4.6-8.el8.x86_64 : Utilities for managing accounts and shadow : password files Repo : BaseOS Matched from: Filename : /etc/default/useradd Filename : /usr/sbin/useradd
Note:
16. How to upgrade the system (specific, minimal or full) to the latest package versions?
Note:
$ sudo dnf upgrade unzip.x86_64
Output: Dependencies resolved. ================================================================================== Package Architecture Version Repository Size =================================================================================== Upgrading: unzip x86_64 6.0-43.el8 BaseOS 195 k Transaction Summary =================================================================================== Upgrade 1 Package Total download size: 195 k Is this ok [y/N]: y
Note:
$ sudo dnf upgrade "minimal-upgrade"
Note:
$ sudo dnf upgrade
Note:
$ dnf distro-sync
17. How to downgrade a specific package?
$ sudo dnf downgrade package-name [version number]
Note:
18. How to view the dnf repository information?
$ sudo dnf repolist
Output: repo id repo name status AppStream CentOS-8 - AppStream 4,933 BaseOS CentOS-8 - Base 1,673 extras CentOS-8 - Extras 20
Note:
$ sudo dnf repolist all
Output: epo id repo name status AppStream CentOS-8 - AppStream enabled: 4,933 AppStream-source CentOS-8 - AppStream Sources disabled BaseOS CentOS-8 - Base enabled: 1,673 BaseOS-source CentOS-8 - BaseOS Sources disabled HighAvailability CentOS-8 - HA disabled cr CentOS-8 - cr disabled extras CentOS-8 - Extras enabled: 20
19. How do I view my DNF transaction history?
$ sudo dnf history
Output:
ID | Command line | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
14 | install wget | 2020-07-13 11:28 | Install | 1
13 | remove wget-1.19.5-8.el8 | 2020-07-13 11:27 | Removed | 1
12 | upgrade wget.x86_64 | 2020-07-13 11:18 | Upgrade | 1
11 | upgrade tcpdump | 2020-07-13 09:11 | Upgrade | 1
10 | upgrade unzip.x86_64 | 2020-07-13 09:02 | Upgrade | 1
9 | reinstall vsftpd | 2020-07-10 17:27 | R | 2
8 | install vsftpd | 2020-07-10 17:10 | Install | 1 < 7 | install vsftpd | 2020-07-10 16:11 | Install | 1 >
6 | remove vsftpd | 2020-07-10 16:05 | Removed | 1
5 | install vsftpd | 2020-07-10 15:24 | Install | 1
4 | remove vsftpd | 2020-07-10 15:24 | Removed | 1
3 | update sudo -y | 2020-07-09 14:43 | Upgrade | 1
2 | install vsftpd | 2020-07-09 14:28 | Install | 1
1 | | 2020-06-21 18:19 | Install | 1348 EE
Note:
$ sudo dnf history info 14
Output: Transaction ID : 14 Begin time : Monday 13 July 2020 11:28:43 AM IST Begin rpmdb : 1331:ff1a9c5ee60280c35a854915fecf8ffe805d6a43 End time : Monday 13 July 2020 11:28:44 AM IST (1 seconds) End rpmdb : 1332:4e8d791ac05740b57ba4f15f8bfe469c306944ea User : linuxteck Return-Code : Success Releasever : 8 Command Line : install wget Packages Altered: Install wget-1.19.5-8.el8_1.1.x86_64 @AppStream
Note:
$ sudo dnf history undo 14
Output:
Undoing transaction 14, from Monday 13 July 2020 11:28:43 AM IST
Install wget-1.19.5-8.el8_1.1.x86_64 @AppStream
Dependencies resolved.
=============================================================================================
Package Architecture Version Repository Size
==============================================================================================
Removing:
wget x86_64 1.19.5-8.el8_1.1 @AppStream 2.9 M
Transaction Summary
===============================================================================================
Remove 1 Package
Freed space: 2.9 M
Is this ok [y/N]: y
Note:
$ sudo dnf history redo 14
Output:
Repeating transaction 14, from Monday 13 July 2020 11:28:43 AM IST
Install wget-1.19.5-8.el8_1.1.x86_64 @AppStream
=============================================================================================
Package Architecture Version Repository Size
=============================================================================================
Installing:
wget x86_64 1.19.5-8.el8_1.1 AppStream 735 k
Transaction Summary
==============================================================================================
Install 1 Package
Total download size: 735 k
Installed size: 2.9 M
Is this ok [y/N]: y
20. How to get the help option for DNF in the command line?
$ man dnf
$ info dnf
$ dnf help
Note:
Thank you! I hope this article will help you to understand the 'dnf' command with examples. Drop me your feedback/comments. If you like this article, kindly share it and it may help others as well.
A few dnf references are collected from this site
Thank you!