Cyberithub

31 Useful DNF Command examples for RPM Package Management in Fedora/RHEL/CentOS

Table of Contents

Advertisements

In this article, I will take you through 31 Useful DNF Command Examples for RPM Package Management in Fedora/RHEL/CentOS. If you are a Linux Professional then you might be aware of yum command which is being used frequently to download packages, update or upgrade packages etc till RHEL/CentOS 7 but from RHEL/CentOS 8 there is a new tool called DNF comes up replaced legacy YUM tool. DNF is also known as Dandified YUM which is considered as next generation tool for RPM Package Management in Linux. In this session, we will go through multiple examples of DNF Command to understand its usages in RPM Package Management in Linux.

31 Useful DNF Command examples for RPM Package Management in Fedora/RHEL/CentOS 2

DNF Command Examples for RPM Package Management in Linux

Also Read: 33 Practical Examples of ulimit command in Linux/Unix for Professionals

Example 1: How to Check DNF Command Version

If you want to check dnf tool version then you need to use dnf --version command as shown below. As you can see from below output, current dnf command version is 4.2.7.

[root@localhost ~]# dnf --version
4.2.7
Installed: dnf-0:4.2.7-7.el8_1.noarch at Mon 23 Mar 2020 11:02:17 AM GMT
Built : CentOS Buildsys <bugs@centos.org> at Thu 19 Dec 2019 03:44:23 PM GMT

Installed: rpm-0:4.14.2-25.el8.x86_64 at Mon 23 Mar 2020 10:59:10 AM GMT
Built : CentOS Buildsys <bugs@centos.org> at Fri 08 Nov 2019 10:56:14 PM GMT

NOTE:

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.

 

Example 2: How to Update Your System Using DNF Command

If you want to update your System then you need to use dnf update command as shown below. This command will search and install all the latest updates from Enabled Repositories.

[root@localhost ~]# dnf update 
Last metadata expiration check: 0:00:09 ago on Wed 01 Jul 2020 10:47:34 PM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package                     Architecture  Version                                 Repository Size
========================================================================================================================================================================
Installing:
kernel-core                 x86_64        4.18.0-193.6.3.el8_2                     BaseOS     28 M
Upgrading:
alsa-lib                    x86_64        1.2.1.2-3.el8                            AppStream  441 k
container-selinux           noarch        2:2.124.0-1.module_el8.2.0+305+5e198a41  AppStream  47 k
containers-common           x86_64        1:0.1.40-11.module_el8.2.0+377+92552693  AppStream  50 k
fribidi                     x86_64        1.0.4-8.el8                              AppStream  89 k
fuse-overlayfs              x86_64        0.7.2-5.module_el8.2.0+305+5e198a41      AppStream  60 k
git                         x86_64        2.18.4-2.el8_2                           AppStream  186 k
git-core                    x86_64        2.18.4-2.el8_2                           AppStream  4.0 M
git-core-doc                noarch        2.18.4-2.el8_2                           AppStream  2.3 M
gtk-update-icon-cache       x86_64        3.22.30-5.el8                            AppStream  32 k
gtk3                        x86_64        3.22.30-5.el8                            AppStream  4.5 M
java-1.8.0-openjdk-headless x86_64        1:1.8.0.252.b09-3.el8_2                  AppStream  33 M
java-11-openjdk             x86_64        1:11.0.7.10-1.el8_1                      AppStream  247 k
java-11-openjdk-devel       x86_64        1:11.0.7.10-1.el8_1                      AppStream  3.3 M
java-11-openjdk-headless    x86_64        1:11.0.7.10-1.el8_1                      AppStream  40 M
libX11                      x86_64        1.6.8-3.el8                              AppStream  611 k

NOTE:

Please note that we are using this command without -y so it will ask for confirmation before installing all the updates.

 

Example 3: How to Install a Package Using dnf command in Linux

If you want to install a package then you need to use below dnf command. In this example, we are trying to install unzip package using dnf install unzip command. This command will find and install the latest available version of unzip package from Repository.

[root@localhost ~]# dnf install unzip
Last metadata expiration check: 0:01:35 ago on Wed 01 Jul 2020 10:47:34 PM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package   Architecture Version    Repository Size
========================================================================================================================================================================
Installing:
unzip     x86_64       6.0-43.el8   BaseOS   195 k

Transaction Summary
========================================================================================================================================================================
Install 1 Package

Total download size: 195 k
Installed size: 413 k

 

Example 4: How to Check DNF Command History

If you want to check all the dnf command history then you need to use dnf history command as shown below. This command is very similar to history command that you are very much familiar with. This is very useful command in determining what you ran in the past particularly when you got into some kind of dnf command related error.

[root@localhost ~]# dnf history
ID|     Command line         |   Date and time  | Action(s)     | Altered
-------------------------------------------------------------------------------
8 | install nodejs           | 2020-07-01 21:19 | I, U          | 8
7 | -y groupupdate Core Mini | 2020-03-23 07:19 | Install       | 46 ##
6 | install -y kernel-core   | 2020-03-23 07:17 | Install       | 1
5 | -y --releasever=8 --allo | 2020-03-23 06:56 | D, E, I, O, U | 617 E<
4 | upgrade -y epel-release  | 2020-03-23 06:49 | Upgrade       | 1 >
3 | upgrade -y http://mirror | 2020-03-23 06:47 | I, U          | 3 EE
2 | -y upgrade               | 2020-03-23 06:30 | E, I, U       | 55 EE
1 | -y remove yum yum-metada | 2020-03-23 06:27 | Removed       | 4

 

Example 5: How to Install a Package Assuming Yes as Answer 

If you want to install a package assuming yes as answer for the confirmation then you need to use -y option with dnf command as shown below. In this example, we are trying to install httpd package using dnf install httpd -y command.

[root@localhost ~]# dnf install httpd -y
Last metadata expiration check: 0:08:09 ago on Wed 01 Jul 2020 10:47:34 PM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package                       Architecture         Version                             Repository  Size
========================================================================================================================================================================
Installing:
httpd                            x86_64          2.4.37-21.module_el8.2.0+382+15b0afa8  AppStream   1.7 M
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
mailcap                          noarch          2.1.48-3.el8                           BaseOS      39 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

Transaction Summary
========================================================================================================================================================================
Install 10 Packages

Total download size: 2.3 M
Installed size: 6.1 M

 

Example 6: How to Check all Enabled Repo List Using DNF Command 

If you want to check all the enabled repo list then you need to use dnf repolist command as shown below. This dnf command will provide the Enable Repo Id, Repo Name and Status as specified below.

[root@localhost ~]# dnf repolist
Last metadata expiration check: 0:11:12 ago on Wed 01 Jul 2020 10:47:34 PM EDT.
repo id           repo name                                              status
AppStream         CentOS-8 - AppStream                                   4,926
BaseOS            CentOS-8 - Base                                        1,671
*epel             Extra Packages for Enterprise Linux 8 - x86_64         5,917
*epel-modular     Extra Packages for Enterprise Linux Modular 8 - x86_64 15
extras            CentOS-8 - Extras                                      20
google-cloud-sdk  Google Cloud SDK                                       1,544

 

Example 7: How to Check all Enabled and Disabled Repo List Using DNF Command

If you want to check all enabled as well as disabled repo then you need to use dnf repolist all command as shown below. This dnf command will not only show the enabled but disabled repository as well. This is very helpful in determining which repo is currently enabled and which one are not.

[root@localhost ~]# dnf repolist all
Last metadata expiration check: 0:13:26 ago on Wed 01 Jul 2020 10:47:34 PM EDT.
repo id                  repo name                                         status
AppStream           CentOS-8 - AppStream                                   enabled: 4,926
AppStream-source    CentOS-8 - AppStream Sources                           disabled
BaseOS              CentOS-8 - Base                                        enabled: 1,671
BaseOS-source       CentOS-8 - BaseOS Sources                              disabled
Devel               CentOS-8 - Devel WARNING! FOR BUILDROOT USE ONLY!      disabled
HighAvailability    CentOS-8 - HA                                          disabled
PowerTools          CentOS-8 - PowerTools                                  disabled
base-debuginfo      CentOS-8 - Debuginfo                                   disabled
c8-media-AppStream  CentOS-AppStream-8 - Media                             disabled
c8-media-BaseOS     CentOS-BaseOS-8 - Media                                disabled
centosplus          CentOS-8 - Plus                                        disabled
centosplus-source   CentOS-8 - Plus Sources                                disabled
cr                  CentOS-8 - cr                                          disabled
*epel               Extra Packages for Enterprise Linux 8 - x86_64         enabled: 5,917
epel-debuginfo      Extra Packages for Enterprise Linux 8 - x86_64 - Debug disabled

 

Example 8: How to Check for Available Updates using DNF Command

If you want to check all available updates then you  need to use dnf check-update command as shown below. This dnf command will only show the available updates, it will not install any updates. So that you can choose if you want to install any specific updates rather than installing all of them.

[root@localhost ~]# dnf check-update
Last metadata expiration check: 0:15:07 ago on Wed 01 Jul 2020 10:47:34 PM EDT.

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
alsa-lib.x86_64 1.2.1.2-3.el8 AppStream
audit.x86_64 3.0-0.17.20191104git1c2f876.el8 BaseOS
audit-libs.x86_64 3.0-0.17.20191104git1c2f876.el8 BaseOS
bind-export-libs.x86_64 32:9.11.13-3.el8 BaseOS
centos-gpg-keys.noarch 8.2-2.2004.0.1.el8 BaseOS
centos-obsolete-packages.noarch 8-4 BaseOS
centos-release.x86_64 8.2-2.2004.0.1.el8 BaseOS
centos-repos.x86_64 8.2-2.2004.0.1.el8 BaseOS
container-selinux.noarch 2:2.124.0-1.module_el8.2.0+305+5e198a41 AppStream
containers-common.x86_64 1:0.1.40-11.module_el8.2.0+377+92552693 AppStream
coreutils.x86_64 8.30-7.el8_2.1 BaseOS
coreutils-common.x86_64 8.30-7.el8_2.1 BaseOS
crypto-policies.noarch 20191128-2.git23e1bf1.el8 BaseOS

 

Example 9: How to List all available and Installed Packages using DNF Command

If you want to list all available as well as installed packages then you need to use dnf list command as shown below. This is probably the best dnf command I have ever encountered with which will basically show you the sum of all packages including available and installed packages.

[root@localhost ~]# dnf list
Last metadata expiration check: 0:17:20 ago on Wed 01 Jul 2020 10:47:34 PM EDT.
Installed Packages
NetworkManager.x86_64 1:1.20.0-5.el8_1 @BaseOS
NetworkManager-libnm.x86_64 1:1.20.0-5.el8_1 @BaseOS
NetworkManager-team.x86_64 1:1.20.0-5.el8_1 @BaseOS
NetworkManager-tui.x86_64 1:1.20.0-5.el8_1 @BaseOS
abattis-cantarell-fonts.noarch 0.0.25-4.el8 @AppStream
acl.x86_64 2.2.53-1.el8 @BaseOS
adwaita-cursor-theme.noarch 3.28.0-2.el8 @AppStream
adwaita-icon-theme.noarch 3.28.0-2.el8 @AppStream
aic94xx-firmware.noarch 30-6.el7 @System
alsa-firmware.noarch 1.0.29-6.el8 @AppStream
alsa-lib.x86_64 1.1.9-4.el8 @AppStream
alsa-tools-firmware.x86_64 1.1.6-1.el8 @AppStream
at-spi2-atk.x86_64 2.26.2-1.el8 @AppStream
at-spi2-core.x86_64 2.28.0-1.el8 @AppStream
atk.x86_64 2.28.1-1.el8 @AppStream
audit.x86_64 3.0-0.10.20180831git0047a6c.el8 @BaseOS
audit-libs.x86_64 3.0-0.10.20180831git0047a6c.el8 @BaseOS
authselect.x86_64 1.1-2.el8 @BaseOS
authselect-compat.x86_64 1.1-2.el8 @AppStream

 

Example 10: How to update an Installed Package Using DNF Command in Linux

If you want to update an installed package then you need to use below dnf update command. In this example, we are trying to update openssl package using dnf update openssl -y command.

[root@localhost ~]# dnf update openssl -y
Last metadata expiration check: 0:19:14 ago on Wed 01 Jul 2020 10:47:34 PM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Upgrading:
openssl x86_64 1:1.1.1c-15.el8 BaseOS 697 k
openssl-libs x86_64 1:1.1.1c-15.el8 BaseOS 1.5 M

Transaction Summary
========================================================================================================================================================================
Upgrade 2 Packages

Total download size: 2.1 M

 

Example 11: How to List All the Installed Packages Using DNF Command in Linux

If you want to list all the installed packages then you need to use dnf list installed command as shown below.

[root@localhost ~]# dnf list installed
NetworkManager.x86_64 1:1.20.0-5.el8_1 @BaseOS
NetworkManager-libnm.x86_64 1:1.20.0-5.el8_1 @BaseOS
NetworkManager-team.x86_64 1:1.20.0-5.el8_1 @BaseOS
NetworkManager-tui.x86_64 1:1.20.0-5.el8_1 @BaseOS
abattis-cantarell-fonts.noarch 0.0.25-4.el8 @AppStream
acl.x86_64 2.2.53-1.el8 @BaseOS
adwaita-cursor-theme.noarch 3.28.0-2.el8 @AppStream
adwaita-icon-theme.noarch 3.28.0-2.el8 @AppStream
aic94xx-firmware.noarch 30-6.el7 @System
alsa-firmware.noarch 1.0.29-6.el8 @AppStream
alsa-lib.x86_64 1.1.9-4.el8 @AppStream
alsa-tools-firmware.x86_64 1.1.6-1.el8 @AppStream
at-spi2-atk.x86_64 2.26.2-1.el8 @AppStream
at-spi2-core.x86_64 2.28.0-1.el8 @AppStream
atk.x86_64 2.28.1-1.el8 @AppStream
audit.x86_64 3.0-0.10.20180831git0047a6c.el8 @BaseOS
audit-libs.x86_64 3.0-0.10.20180831git0047a6c.el8 @BaseOS
authselect.x86_64 1.1-2.el8 @BaseOS
authselect-compat.x86_64 1.1-2.el8 @AppStream

 

Example 12: How to Download a File from Repository Using DNF Command

If you want to download a package then you need to use below dnf download command. In this example, we are trying to download unzip package using dnf download unzip command.

[root@localhost ~]# dnf download unzip
Last metadata expiration check: 0:24:15 ago on Wed 01 Jul 2020 10:47:34 PM EDT.
unzip-6.0-43.el8.x86_64.rpm 1.1 MB/s | 195 kB 00:00
[root@localhost ~]# ls -ltr unzip-6.0-43.el8.x86_64.rpm
-rw-r--r--. 1 root root 199620 Jul 1 23:11 unzip-6.0-43.el8.x86_64.rpm

 

Example 13: How to Remove a Package Using DNF Command

If you want to remove a package then you need to use below dnf remove command. In this example, we are trying to remove unzip package using dnf remove unzip command.

[root@localhost ~]# dnf remove unzip
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Removing:
unzip x86_64 6.0-43.el8 @BaseOS 413 k

Transaction Summary
========================================================================================================================================================================
Remove 1 Package

Freed space: 413 k

 

Example 14: How to Check All Available Packages from Repository Using DNF Command

If you want to check all the available packages from Repository then you need to use dnf list available command as shown below.

[root@localhost ~]# dnf list available 
Last metadata expiration check: 0:00:09 ago on Wed 01 Jul 2020 11:29:57 PM EDT.
Available                             Packages
3proxy.x86_64 0.8.13-1.el8            epel
BackupPC.x86_64 4.3.2-1.el8           epel
BackupPC-XS.x86_64 0.59-3.el8         epel
CCfits.x86_64 2.5-13.el8              epel
CCfits-devel.x86_64 2.5-13.el8        epel
CCfits-doc.noarch 2.5-13.el8          epel
CGSI-gSOAP.x86_64 1.3.11-7.el8        epel
CGSI-gSOAP-devel.x86_64 1.3.11-7.el8  epel
CUnit.i686 2.1.3-17.el8               AppStream
CUnit.x86_64 2.1.3-17.el8             AppStream
Field3D.x86_64 1.7.2-16.el8           epel
Field3D-devel.x86_64 1.7.2-16.el8     epel
FoXlibf.x86_64 4.1.2-12.el8           epel
FoXlibf-devel.x86_64 4.1.2-12.el8     epel

 

Example 15: How to Search a Package from Repository Using DNF Command

If you want to search a package from repository then you need to use below dnf search command. In this example, we are trying to search unzip package using dnf search unzip command. This command will search all the packages related to unzip keyword from Enabled Repositories and will show you in the output for download or installation.

[root@localhost ~]# dnf search unzip
Last metadata expiration check: 0:01:59 ago on Wed 01 Jul 2020 11:29:57 PM EDT.
===================================================================== Name Exactly Matched: unzip ======================================================================
unzip.x86_64 : A utility for unpacking zip files
unzip.x86_64 : A utility for unpacking zip files
======================================================================== Summary Matched: unzip ========================================================================
perl-PerlIO-gzip.x86_64 : Perl extension to provide a PerlIO layer to gzip/gunzip

 

Example 16: How to Check the Package Name of a Command in Linux

If you want to check the source package of a command then you need to use below dnf provides command. In this example, we are trying to search the package name of command /usr/bin/ls using dnf provides /usr/bin/ls command .

[root@localhost ~]# dnf provides /usr/bin/ls
Last metadata expiration check: 0:03:50 ago on Wed 01 Jul 2020 11:29:57 PM EDT.
coreutils-8.30-6.el8.x86_64 : A set of basic GNU tools commonly used in shell scripts
Repo : @System
Matched from:
Filename : /usr/bin/ls

coreutils-8.30-7.el8_2.1.x86_64 : A set of basic GNU tools commonly used in shell scripts
Repo : BaseOS
Matched from:
Filename : /usr/bin/ls

coreutils-single-8.30-7.el8_2.1.x86_64 : coreutils multicall binary
Repo : BaseOS
Matched from:
Filename : /usr/bin/ls

 

Example 17: How to Remove Cached Packages Using DNF Command

If you want to remove all the cached packages data then you need to use dnf clean all command as shown below. This command is particularly useful when you are trying to use dnf command and in between you are getting some strange error. The very first thing you want to try to resolve this error is to clean up the Cache.

[root@localhost ~]# dnf clean all
45 files removed

 

Example 18: How to Check Information About a Package in Linux

If you want to check information about some package then you need to use below dnf info command. In this example, we are trying to find the information about unzip package using dnf info unzip command.

[root@localhost ~]# dnf info unzip
CentOS-8 - AppStream 342 kB/s | 5.8 MB 00:17
CentOS-8 - Base 2.8 MB/s | 2.2 MB 00:00
CentOS-8 - Extras 432 B/s | 6.7 kB 00:15
Extra Packages for Enterprise Linux Modular 8 - x86_64 71 kB/s | 154 kB 00:02
Extra Packages for Enterprise Linux 8 - x86_64 1.5 MB/s | 7.1 MB 00:04
Google Cloud SDK 4.2 MB/s | 39 MB 00:09
Last metadata expiration check: 0:00:01 ago on Wed 01 Jul 2020 11:38:51 PM EDT.
Installed Packages
Name : unzip
Version : 6.0
Release : 43.el8
Architecture : x86_64
Size : 413 k
Source : unzip-6.0-43.el8.src.rpm
Repository : @System
From repo : BaseOS
Summary : A utility for unpacking zip files
URL : http://www.info-zip.org/UnZip.html
License : BSD
Description : The unzip utility is used to list, test, or extract files from a zip
: archive. Zip archives are commonly found on MS-DOS systems. The zip
: utility, included in the zip package, creates zip archives. Zip and
: unzip are both compatible with archives created by PKWARE(R)'s PKZIP
: for MS-DOS, but the programs' options and default behaviors do differ
: in some respects.
:
: Install the unzip package if you need to list, test or extract files from
: a zip archive.

 

Example 19: How to Build a Cache Using DNF Command in Linux

If you want to build a dnf cache then you need to use dnf makecache command as shown below. This command will build the Cache in few minutes which otherwise would have built slowly and steadily by running multiple dnf command over the time.

[root@localhost ~]# dnf makecache
CentOS-8 - AppStream 762 B/s | 4.3 kB 00:05
CentOS-8 - Base 5.3 kB/s | 3.9 kB 00:00
CentOS-8 - Extras 1.8 kB/s | 1.5 kB 00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64 6.5 kB/s | 8.3 kB 00:01
Extra Packages for Enterprise Linux 8 - x86_64 11 kB/s | 8.6 kB 00:00
Google Cloud SDK 192 B/s | 454 B 00:02
Metadata cache created.

 

Example 20: How to Sync all the Installed Packages with Latest Releases

If you want to sync all the installed packages with latest available releases then you need to use dnf distro-sync command as shown below.

[root@localhost ~]# dnf distro-sync
Last metadata expiration check: 0:01:02 ago on Thu 02 Jul 2020 12:45:46 AM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package                              Architecture  Version                                  Repository Size
========================================================================================================================================================================
Installing:
kernel-core                             x86_64      4.18.0-193.6.3.el8_2                     BaseOS     28 M
Upgrading:
alsa-lib                                x86_64      1.2.1.2-3.el8                            AppStream  441 k
container-selinux                       noarch      2:2.124.0-1.module_el8.2.0+305+5e198a41  AppStream  47 k
containers-common                       x86_64      1:0.1.40-11.module_el8.2.0+377+92552693  AppStream  50 k
fribidi                                 x86_64      1.0.4-8.el8                              AppStream  89 k
fuse-overlayfs                          x86_64      0.7.2-5.module_el8.2.0+305+5e198a41      AppStream  60 k
git                                     x86_64      2.18.4-2.el8_2                           AppStream  186 k
git-core                                x86_64      2.18.4-2.el8_2                           AppStream  4.0 M
git-core-doc                            noarch      2.18.4-2.el8_2                           AppStream  2.3 M
gtk-update-icon-cache                   x86_64      3.22.30-5.el8                            AppStream  32 k

 

Example 21: How to Reinstall a Package Using DNF Command

After installing a package if you see any error related to that package then probably you want to uninstall and install that package again which is same as saying reinstall the package again. So if you want to reinstall a package then you need to use below dnf reinstall command. In this example, we are trying to reinstall unzip package using dnf reinstall unzip command as shown below.

[root@localhost ~]# dnf reinstall unzip
Last metadata expiration check: 0:03:03 ago on Thu 02 Jul 2020 12:45:46 AM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package  Architecture  Version        Repository  Size
========================================================================================================================================================================
Reinstalling:
unzip      x86_64       6.0-43.el8      BaseOS    195 k

Transaction Summary
========================================================================================================================================================================

Total download size: 195 k
Installed size: 413 k

 

Example 22: How to Remove Orphan Packages Using DNF Command

If you want to remove all the Orphan packages then you need to use below dnf autoremove -y command. This command is very useful to remove all those packages which got installed as dependent packages and now it is of no use. Hence these types of packages are also called Orphan Packages.

[root@localhost ~]# dnf autoremove -y
Last metadata expiration check: 0:04:27 ago on Thu 02 Jul 2020 12:45:46 AM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Removing:
authselect x86_64 1.1-2.el8 @BaseOS 82 k
authselect-compat x86_64 1.1-2.el8 @AppStream 82 k
authselect-libs x86_64 1.1-2.el8 @BaseOS 771 k
centos-obsolete-packages noarch 8-2 @BaseOS 150
grub2-tools-efi x86_64 1:2.02-78.el8_1.1 @BaseOS 2.0 M
netconsole-service noarch 10.00.4-1.el8 @BaseOS 5.4 k
network-scripts x86_64 10.00.4-1.el8 @BaseOS 174 k
network-scripts-team x86_64 1.28-4.el8 @BaseOS 6.6 k
oddjob x86_64 0.34.4-7.el8 @AppStream 182 k
oddjob-mkhomedir x86_64 0.34.4-7.el8 @AppStream 89 k
python2-pyyaml x86_64 3.12-16.module_el8.1.0+219+cf9e6ac9 @AppStream 674 k
python3-pytoml noarch 0.1.14-5.git7dea353.el8 @AppStream 32 k
readonly-root noarch 10.00.4-1.el8 @BaseOS 8.2 k
systemd-container x86_64 239-18.el8_1.4 @BaseOS 1.9 M

Transaction Summary
========================================================================================================================================================================
Remove 14 Packages

Freed space: 5.9 M

 

Example 23: How to List All Group packages Using DNF Command

If you want to list all group packages then you need to use dnf grouplist command as shown below.

[root@localhost ~]# dnf grouplist
CentOS-8 - AppStream 6.0 kB/s | 4.3 kB 00:00
CentOS-8 - Base 6.8 kB/s | 3.9 kB 00:00
CentOS-8 - Extras 256 B/s | 1.5 kB 00:06
Extra Packages for Enterprise Linux Modular 8 - x86_64 6.5 kB/s | 8.3 kB 00:01
Extra Packages for Enterprise Linux 8 - x86_64 4.3 kB/s | 8.6 kB 00:02
Google Cloud SDK 226 B/s | 454 B 00:02
Available Environment Groups:
Server with GUI
Server
Minimal Install
Workstation
KDE Plasma Workspaces
Virtualization Host
Custom Operating System
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
Fedora Packager
Xfce

 

Example 24: How to Install a Group Package Using DNF Command

If you want to install a group package then you need to use below dnf groupinstall command. In this example, we are trying to install Graphical Administration Tools using dnf groupinstall "Graphical Administration Tools" -y command.

[root@localhost ~]# dnf groupinstall "Graphical Administration Tools" -y
Last metadata expiration check: 0:02:22 ago on Thu 02 Jul 2020 12:53:16 AM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Installing Groups:
Graphical Administration Tools

Transaction Summary
========================================================================================================================================================================

 

Example 25: How to Remove a Group Package Using DNF Command

If you want to remove a group package then you need to use below dnf groupremove command. In this example, we are trying to remove Graphical Administration Tools using dnf groupremove "Graphical Administration Tools" -y command.

[root@localhost ~]# dnf groupremove "Graphical Administration Tools" -y
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Removing Groups:
Graphical Administration Tools

Transaction Summary
========================================================================================================================================================================

Complete!

 

Example 26: How to Update Group Package Using DNF Command

If you want to update a group package then you need to use below dnf groupupdate command. In this example, we are trying to update group package Graphical Administration Tools using dnf groupupdate "Graphical Administration Tools" -y command.

[root@localhost ~]# dnf groupupdate "Graphical Administration Tools" -y
Last metadata expiration check: 0:21:51 ago on Thu 02 Jul 2020 12:53:16 AM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Installing Groups:
Graphical Administration Tools

Transaction Summary
========================================================================================================================================================================

Complete!

 

Example 27: How to Downgrade a Package Using DNF Command

If you want to downgrade a package then you need to use below dnf downgrade command. In this example, we are trying to downgrade openssl package version using dnf downgrade openssl command. As you can see from below output, as of now there is only one version of Openssl package installed hence it cannot be downgraded.

[root@localhost ~]# dnf downgrade openssl
Last metadata expiration check: 0:25:13 ago on Thu 02 Jul 2020 12:53:16 AM EDT.
Package openssl of lowest version already installed, cannot downgrade it.
Error: No packages marked for downgrade.

 

Example 28: How to Enable a Repo and Install Packages Using DNF Command

If you want to enable a repo and install some package from that then you need to use below dnf command. In this example, we are trying to enable a repo epel and installing unzip package from that using dnf install --enablerepo=epel unzip command as shown below.

[root@localhost ~]# dnf install --enablerepo=epel unzip
CentOS-8 - AppStream 5.0 kB/s | 4.3 kB 00:00
CentOS-8 - Base 7.9 kB/s | 3.9 kB 00:00
CentOS-8 - Extras 3.3 kB/s | 1.5 kB 00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64 9.7 kB/s | 8.3 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 11 kB/s | 8.6 kB 00:00
Google Cloud SDK 196 B/s | 454 B 00:02
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Installing:
unzip x86_64 6.0-43.el8 BaseOS 195 k

Transaction Summary
========================================================================================================================================================================
Install 1 Package

Total download size: 195 k
Installed size: 413 k

 

Example 29: How to Upgrade a Package Using DNF Command 

If you want to upgrade a package to some specific version then you need to use below dnf upgrade-to command. In this example, we are trying to upgrade unzip package to unzip-6.0-43.el8.x86_64 version by using dnf upgrade-to unzip-6.0-43.el8.x86_64 command.

[root@localhost ~]# dnf upgrade-to unzip-6.0-43.el8.x86_64

 

Example 30: How to check help of a DNF command option

If you want to check all the available help for some dnf command option then you need to use below dnf help command. In this example, we are trying to check all the help available for upgrade option using dnf help upgrade command.

[root@localhost ~]# dnf help upgrade
usage: dnf upgrade [-c [config file]] [-q] [-v] [--version]
[--installroot [path]] [--nodocs] [--noplugins]
[--enableplugin [plugin]] [--disableplugin [plugin]]
[--releasever RELEASEVER] [--setopt SETOPTS]
[--skip-broken] [-h] [--allowerasing] [-b | --nobest] [-C]
[-R [minutes]] [-d [debug level]] [--debugsolver]
[--showduplicates] [-e ERRORLEVEL] [--obsoletes]
[--rpmverbosity [debug level name]] [-y] [--assumeno]
[--enablerepo [repo]] [--disablerepo [repo] | --repo
[repo]] [--enable | --disable] [-x [package]]
[--disableexcludes [repo]] [--repofrompath [repo,path]]
[--noautoremove] [--nogpgcheck] [--color COLOR] [--refresh]
[-4] [-6] [--destdir DESTDIR] [--downloadonly]
[--comment COMMENT] [--bugfix] [--enhancement]
[--newpackage] [--security] [--advisory ADVISORY]
[--bz BUGZILLA] [--cve CVES]
[--sec-severity {Critical,Important,Moderate,Low}]
[--forcearch ARCH]
[PACKAGE [PACKAGE ...]]

 

Example 31: How to Check all the Other Options of DNF Command 

If you want to check all the options available with dnf command then you need to use dnf help command as shown below.

[root@localhost ~]# dnf help
usage: dnf [options] COMMAND

List of Main Commands:

alias List or create command aliases
autoremove remove all unneeded packages that were originally installed as dependencies
check check for problems in the packagedb
check-update check for available package upgrades
clean remove cached data
deplist List package's dependencies and what packages provide them
distro-sync synchronize installed packages to the latest available versions
downgrade Downgrade a package
group display, or use, the groups information
help display a helpful usage message
history display, or use, the transaction history
info display details about a package or group of packages
install install a package or packages on your system
list list a package or groups of packages

 

 

Popular Recommendations:-

20 Popular Examples of cat command in Linux/Unix for Beginners

How to Install AWS CLI in Linux (RedHat/CentOS 7/8) Using 6 Easy Steps

11 Useful LVM(lvcreate, pvcreate and vgcreate) command examples on Linux

How to Install and Configure FTP Server(vsftpd) in Linux (RedHat/CentOS 7/8) Using 8 Easy Steps

20 Useful Linux History Command Examples | Bash Command History

How to Install PHP on Ubuntu 18.04

How to Install Rust Programming Language in Linux Using 6 Best Steps

How to Install Ruby on Ubuntu 18.04 with Easy Steps

How to Install Ruby on CentOS/RedHat 7 in 5 Easy Steps

Install Node.js in 6 Easy Steps on Ubuntu 18.04

How to Install NVM for Node.js on Ubuntu 18.04

How to Limit CPU Usage of a Process with CPULimit in Linux (RHEL/CentOS 7/8)

DNF Command Reference

Leave a Comment