CentOS 8 Package Management with DNF on the Command Line

DNF stands for Dandified YUM is a software package manager for RPM-based Linux distributions. It is used to install, update and remove packages in the Fedora/RHEL/CentOS operating system. It is the default package manager of Fedora 22, CentOS8 and RHEL8. DNF is the next generation version of YUM and intended to be the replacement for YUM in RPM-based systems. DNF is powerful and has robust features than you'll find in yum. DNF makes it easy to maintain groups of packages and capable of automatically resolving dependency issues.

In this tutorial, we will explain how to manage package with DNF on CentOS 8.

Requirements

  • A server running CentOS 8.
  • A root password is setup to your server.

Install DNF

By default, DNF is pre-installed in CentOS 8 operating system. If not installed, you can install it by running the following command:

yum install dnf

Next, you can check the version of DNF with the following command:

dnf --version

You should see the following output:

4.0.9
  Installed: dnf-0:4.0.9.2-5.el8.noarch at Friday 04 October 2019 05:27:09 AM GMT
  Built    : CentOS Buildsys <[email protected]> at Monday 13 May 2019 07:35:13 PM GMT

  Installed: rpm-0:4.14.2-9.el8.x86_64 at Friday 04 October 2019 05:20:17 AM GMT
  Built    : CentOS Buildsys <[email protected]> at Saturday 11 May 2019 02:04:19 AM GMT

List Installed and Available Packages

You can list all the installed packages on your system with the following command:

dnf list installed

You should see all the installed packages in the following output:

Installed Packages
NetworkManager.x86_64                 1:1.14.0-14.el8                                        @anaconda 
NetworkManager-config-server.noarch   1:1.14.0-14.el8                                        @anaconda 
NetworkManager-libnm.x86_64           1:1.14.0-14.el8                                        @anaconda 
NetworkManager-team.x86_64            1:1.14.0-14.el8                                        @anaconda 
NetworkManager-tui.x86_64             1:1.14.0-14.el8                                        @anaconda 
PackageKit.x86_64                     1.1.12-2.el8                                           @AppStream
PackageKit-glib.x86_64                1.1.12-2.el8                                           @AppStream
acl.x86_64                            2.2.53-1.el8                                           @anaconda 
adcli.x86_64                          0.8.2-2.el8                                            @anaconda 
at.x86_64                             3.1.20-11.el8                                          @anaconda 
attr.x86_64                           2.4.48-3.el8                                           @anaconda 
audit.x86_64                          3.0-0.10.20180831git0047a6c.el8                        @anaconda 
audit-libs.x86_64                     3.0-0.10.20180831git0047a6c.el8                        @anaconda 
authselect.x86_64                     1.0-13.el8                                             @anaconda 
authselect-compat.x86_64              1.0-13.el8                                             @AppStream
authselect-libs.x86_64                1.0-13.el8                                             @anaconda 
avahi-libs.x86_64                     0.7-19.el8                                             @anaconda 
basesystem.noarch                     11-5.el8                                               @anaconda 

You can also list all installed and available packages with the following command:

dnf list

You should see the following output:

Last metadata expiration check: 4 days, 22:47:10 ago on Friday 04 October 2019 02:14:39 AM EDT.
Installed Packages
NetworkManager.x86_64                                      1:1.14.0-14.el8                                        @anaconda             
NetworkManager-config-server.noarch                        1:1.14.0-14.el8                                        @anaconda             
NetworkManager-libnm.x86_64                                1:1.14.0-14.el8                                        @anaconda             
NetworkManager-team.x86_64                                 1:1.14.0-14.el8                                        @anaconda             
NetworkManager-tui.x86_64                                  1:1.14.0-14.el8                                        @anaconda             
PackageKit.x86_64                                          1.1.12-2.el8                                           @AppStream            
PackageKit-glib.x86_64                                     1.1.12-2.el8                                           @AppStream            
acl.x86_64                                                 2.2.53-1.el8                                           @anaconda             
adcli.x86_64                                               0.8.2-2.el8                                            @anaconda             
at.x86_64                                                  3.1.20-11.el8                                          @anaconda             
attr.x86_64                                                2.4.48-3.el8                                           @anaconda             
audit.x86_64                                               3.0-0.10.20180831git0047a6c.el8                        @anaconda             
audit-libs.x86_64                                          3.0-0.10.20180831git0047a6c.el8                        @anaconda             
authselect.x86_64                                          1.0-13.el8                                             @anaconda             
authselect-compat.x86_64                                   1.0-13.el8                                             @AppStream            
authselect-libs.x86_64                                     1.0-13.el8                                             @anaconda             
avahi-libs.x86_64                                          0.7-19.el8                                             @anaconda             
:
:

You can also list only available packages with the following command:

dnf list available

You should see the following output:

Last metadata expiration check: 4 days, 22:48:21 ago on Friday 04 October 2019 02:14:39 AM EDT.
Available Packages
BackupPC.src                                               4.3.1-2.el8                                      epel-source           
BackupPC.x86_64                                            4.3.1-2.el8                                      epel                  
BackupPC-XS.src                                            0.59-3.el8                                       epel-source           
BackupPC-XS.x86_64                                         0.59-3.el8                                       epel                  
BackupPC-XS-debuginfo.x86_64                               0.59-3.el8                                       epel-debuginfo        
BackupPC-XS-debugsource.x86_64                             0.59-3.el8                                       epel-debuginfo        
BackupPC-debuginfo.x86_64                                  4.3.1-2.el8                                      epel-debuginfo        
BackupPC-debugsource.x86_64                                4.3.1-2.el8                                      epel-debuginfo        
CGSI-gSOAP.src                                             1.3.11-7.el8                                     epel-source           
CGSI-gSOAP.x86_64                                          1.3.11-7.el8                                     epel                  
CGSI-gSOAP-debuginfo.x86_64                                1.3.11-7.el8                                     epel-debuginfo        
CGSI-gSOAP-debugsource.x86_64                              1.3.11-7.el8                                     epel-debuginfo        
CGSI-gSOAP-devel.x86_64                                    1.3.11-7.el8                                     epel                  

Search and Install Package

You can search any package you want to install with the following command:

dnf search httpd

You should see the following output:

========================================================= Name Exactly Matched: httpd =========================================================
httpd.x86_64 : Apache HTTP Server
======================================================== Name & Summary Matched: httpd ========================================================
centos-logos-httpd.noarch : CentOS-related icons and pictures used by httpd
keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
python3-keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
============================================================= Name Matched: httpd =============================================================
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
httpd-manual.noarch : Documentation for the Apache HTTP server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
httpd-filesystem.noarch : The basic directory layout for the Apache HTTP server
=========================================================== Summary Matched: httpd ============================================================
mod_dav_svn.x86_64 : Apache httpd module for Subversion server
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server

You can now install httpd package with the following command:

dnf install httpd

To reinstall the package httpd, run the following command:

dnf reinstall httpd

In some cases, you will require to download the packages without installing it. You can download a specific package with the following command:

dnf download httpd

You can also see details of package httpd with the following command:

dnf info httpd

You should get the following output:

Last metadata expiration check: 0:01:02 ago on Wednesday 09 October 2019 01:07:23 AM EDT.
Available Packages
Name         : httpd
Version      : 2.4.37
Release      : 11.module_el8.0.0+172+85fc1f40
Arch         : x86_64
Size         : 1.7 M
Source       : httpd-2.4.37-11.module_el8.0.0+172+85fc1f40.src.rpm
Repo         : AppStream
Summary      : Apache HTTP Server
URL          : https://httpd.apache.org/
License      : ASL 2.0
Description  : The Apache HTTP Server is a powerful, efficient, and extensible
             : web server.

Update System Packages

First, you can check updates for all the system packages on your system with the following command:

dnf check-update

You should get the following output:

Last metadata expiration check: 0:00:10 ago on Wednesday 09 October 2019 01:10:16 AM EDT.
bind-export-libs.x86_64           32:9.11.4-17.P2.el8_0.1            BaseOS     
bind-libs.x86_64                  32:9.11.4-17.P2.el8_0.1            AppStream  
bind-libs-lite.x86_64             32:9.11.4-17.P2.el8_0.1            AppStream  
bind-license.noarch               32:9.11.4-17.P2.el8_0.1            AppStream  
bind-utils.x86_64                 32:9.11.4-17.P2.el8_0.1            AppStream  
bpftool.x86_64                    4.18.0-80.7.1.el8_0                BaseOS     
cockpit.x86_64                    185.1-1.el8_0                      BaseOS     
cockpit-bridge.x86_64             185.1-1.el8_0                      BaseOS     
cockpit-system.noarch             185.1-1.el8_0                      BaseOS     
cockpit-ws.x86_64                 185.1-1.el8_0                      BaseOS     
epel-release.noarch               8-6.el8                            epel       
epel-release.src                  8-6.el8                            epel-source
iptables.x86_64                   1.8.2-9.el8_0.1                    BaseOS     
iptables-ebtables.x86_64          1.8.2-9.el8_0.1                    BaseOS     
iptables-libs.x86_64              1.8.2-9.el8_0.1                    BaseOS     
kernel.x86_64                     4.18.0-80.7.1.el8_0                BaseOS     
kernel-core.x86_64                4.18.0-80.7.1.el8_0                BaseOS     
kernel-modules.x86_64             4.18.0-80.7.1.el8_0                BaseOS     
kernel-tools.x86_64               4.18.0-80.7.1.el8_0                BaseOS     
kernel-tools-libs.x86_64          4.18.0-80.7.1.el8_0                BaseOS     

You can now update all the packages installed in your system with the following command:

dnf update

To update the specific package, run the following command:

dnf update httpd

List and Install Group Packages

You can list all group packages with the following command:

dnf grouplist

You should get the following list:

Last metadata expiration check: 0:03:42 ago on Wednesday 09 October 2019 01:10:16 AM EDT.
Available Environment Groups:
   Server with GUI
   Minimal Install
   Workstation
   KDE Plasma Workspaces
   Virtualization Host
   Custom Operating System
Installed Environment Groups:
   Server
Installed Groups:
   Container Management
   Headless Management
Available Groups:
   .NET Core Development
   RPM Development Tools
   Smart Card Support
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Network Servers
   Scientific Support
   Security Tools
   System Tools
   Fedora Packager

Now, install specific Group package with the following command:

dnf groupinstall 'System Tools'

You can also update a Group package with the following command:

dnf groupupdate 'System Tools'

List Repositories

You can list all repositories with the following command:

dnf repolist all

You should see the following output:

Last metadata expiration check: 0:10:39 ago on Wednesday 09 October 2019 01:10:16 AM EDT.
repo id                                    repo name                                                                             status
AppStream                                  CentOS-8 - AppStream                                                                  enabled: 4,928
AppStream-source                           CentOS-8 - AppStream Sources                                                          disabled
BaseOS                                     CentOS-8 - Base                                                                       enabled: 2,713
BaseOS-source                              CentOS-8 - BaseOS Sources                                                             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: 1,816
*epel-debuginfo                            Extra Packages for Enterprise Linux 8 - x86_64 - Debug                                enabled: 1,187
epel-playground                            Extra Packages for Enterprise Linux 8 - Playground - x86_64                           disabled
epel-playground-debuginfo                  Extra Packages for Enterprise Linux 8 - Playground - x86_64 - Debug                   disabled
epel-playground-source                     Extra Packages for Enterprise Linux 8 - Playground - x86_64 - Source                  disabled
*epel-source                               Extra Packages for Enterprise Linux 8 - x86_64 - Source                               enabled:   792
*epel-testing                              Extra Packages for Enterprise Linux 8 - Testing - x86_64                              enabled:   538
*epel-testing-debuginfo                    Extra Packages for Enterprise Linux 8 - Testing - x86_64 - Debug                      enabled:   347
*epel-testing-source                       Extra Packages for Enterprise Linux 8 - Testing - x86_64 - Source                     enabled:   216
extras                                     CentOS-8 - Extras                                                                     enabled:     3
extras-source                              CentOS-8 - Extras Sources                                                             disabled
fasttrack                                  CentOS-8 - fasttrack                                                                  disabled

Now, list only enabled repositories on the system with the following command:

dnf repolist

You should see the following output:

Last metadata expiration check: 0:12:14 ago on Wednesday 09 October 2019 01:10:16 AM EDT.
repo id                                        repo name                                                                                 status
AppStream                                      CentOS-8 - AppStream                                                                      4,928
BaseOS                                         CentOS-8 - Base                                                                           2,713
*epel                                          Extra Packages for Enterprise Linux 8 - x86_64                                            1,816
*epel-debuginfo                                Extra Packages for Enterprise Linux 8 - x86_64 - Debug                                    1,187
*epel-source                                   Extra Packages for Enterprise Linux 8 - x86_64 - Source                                     792
*epel-testing                                  Extra Packages for Enterprise Linux 8 - Testing - x86_64                                    538
*epel-testing-debuginfo                        Extra Packages for Enterprise Linux 8 - Testing - x86_64 - Debug                            347
*epel-testing-source                           Extra Packages for Enterprise Linux 8 - Testing - x86_64 - Source                           216
extras                                         CentOS-8 - Extras                                                                             3

Remove Packages

You can remove any unwanted package from your system with the following command:

dnf remove httpd

Next, remove unwanted dependencies installed with the package httpd by running the following command:

dnf autoremove

You can clean all the cached packages with the following command:

dnf clean all

You can also remove the group package with the following command:

dnf groupremove 'System Tools'

Conclusion

In the above tutorial, we learned how to manage packages with DNF command on CentOS 8. Feel free to ask me if you have any questions.

Share this page:

Suggested articles

0 Comment(s)

Add comment