dnf Package manager utility RHEL / CentOS 8 / Fedora

ComputerCarriage > Posts > Commands > dnf Package manager utility RHEL / CentOS 8 / Fedora
dnf

dnf Software Package Manager

1. Introduction

2. dnf Features

  • Faster and less memory-intensive operation
  • Package group support, including multiple-repository groups
  • Simple interface
  • DNF runs in both Python 2 / 3
  • libdnf – high-level API for DNF and underlying libraries
  • libsolv – free package dependency solver using a satisfiability algorithm
  • librepo – library providing C and Python API for downloading Linux repo metadata and packages
  • libcomps – An alternative for yum.comps library
  • Dependency calculation based on modern resolving technology
  • C bindings for lower level libraries

3. dnf command options

Find the below table for dnf package options

autoremovedistro-synchistorymakecacheremoveupdateinfo
checkdowngradeinfomarkrepolistupgrade
check-updategroupinstallprovidessearchupgrade-to
cleanhelplistreinstall
dnf options

4. Install the dnf package

From RHEL 8 / CentOS we can use dnf instead of yum, install dnf using yum command

yum install dnf

5. Install a package using dnf

In this section we are going to install httpd package using dnf

[root@control ~]# dnf install httpd
Last metadata expiration check: 0:00:05 ago on Wednesday 06 May 2020 01:20:27 AM IST.
Dependencies resolved.
============================================================
Package Architecture Version Repository Size
============================================================
Installing:
httpd x86_64 2.4.37-16.module_el8.1.0+256+ae790463 AppStream 1.7 M
Installing dependencies:
centos-logos-httpd noarch 80.5-2.el8 AppStream 24 k
httpd-filesystem noarch 2.4.37-
httpd 2.4
Transaction Summary
============================================================
Install 6 Packages
Total download size: 2.0 M
Installed size: 6.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/6): httpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64.rpm 629 kB/s | 1.7 MB 00:02
------------------Output truncated------------------------
Installed:
httpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64
Complete!
[root@control ~]#

6. dnf repo

dnf repolist option list the available repos in the node

[root@server1 ~]# dnf repolist
CentOS-8 - AppStream 2.5 kB/s | 4.3 kB 00:01
CentOS-8 - Base 4.0 kB/s | 3.9 kB 00:00
CentOS-8 - Extras 1.5 kB/s | 1.5 kB 00:01
CentOS-8 - Extras 4.9 kB/s | 5.9 kB 00:01
[root@server1 ~]#

7. Search a package using dnf

When we need to find the matching pattern of the package that we need to install or if we unsure what packages are available we can query and get the list of matched pattern

[root@server1 ~]# dnf search httpd
Last metadata expiration check: 0:01:54 ago on Tuesday 05 May 2020 03:38:28 PM EDT.
==================================================== Name Exactly Matched: httpd ====================================================
httpd.x86_64 : Apache HTTP Server
httpd.x86_64 : Apache HTTP Server
=================================================== Name & Summary Matched: httpd ===================================================
centos-logos-httpd.noarch : CentOS-related icons and pictures used by httpd
centos-logos-httpd.noarch : CentOS-related icons and pictures used by httpd
-------------- Output Truncated-------------------
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
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
====================================================== 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
[root@server1 ~]#

8. repoquery options usage

1. Querying a package with dnf

If we want to know what are the file that are available in the httpd package use the below command

[root@server1 ~]# dnf repoquery --requires httpd
Last metadata expiration check: 0:03:36 ago on Tuesday 05 May 2020 03:38:28 PM EDT.
/bin/sh
/etc/mime.types
httpd-filesystem
httpd-filesystem = 2.4.37-16.module_el8.1.0+256+ae790463
httpd-tools = 2.4.37-16.module_el8.1.0+256+ae790463
libapr-1.so.0()(64bit)
libaprutil-1.so.0()(64bit)
libbrotlienc.so.1()(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libcrypt.so.1()(64bit)
libcrypt.so.1(XCRYPT_2.0)(64bit)
libdl.so.2()(64bit)
libexpat.so.1()(64bit)
liblua-5.3.so()(64bit)
libm.so.6()(64bit)
libpcre.so.1()(64bit)
libpthread.so.0()(64bit)
libpthread.so.0(GLIBC_2.2.5)(64bit)
libselinux.so.1()(64bit)
libsystemd.so.0()(64bit)
libsystemd.so.0(LIBSYSTEMD_209)(64bit)
libz.so.1()(64bit)
mod_http2
rtld(GNU_HASH)
system-logos-httpd
systemd-units
[root@server1 ~]#

2. Dependency resolve using dnf

Suppose we need to find the list of dependency package that are required to install along with the queried package, using — resolve option we can find out the dependency packages

[root@server1 ~]# dnf repoquery --requires httpd --resolve
Last metadata expiration check: 0:04:55 ago on Tuesday 05 May 2020 03:38:28 PM EDT.
apr-0:1.6.3-9.el8.x86_64
apr-util-0:1.6.1-6.el8.x86_64
bash-0:4.4.19-10.el8.x86_64
glibc-0:2.28-72.el8_1.1.i686
glibc-0:2.28-72.el8_1.1.x86_64
httpd-filesystem-0:2.4.37-16.module_el8.1.0+256+ae790463.noarch
httpd-tools-0:2.4.37-16.module_el8.1.0+256+ae790463.x86_64
systemd-libs-0:239-18.el8_1.5.x86_64
zlib-0:1.2.11-10.el8.x86_64
[root@server1 ~]#

3. Displays all available packages matching httpd*

Displays all available packages matching httpd*:

[root@server1 ~]# dnf repoquery 'httpd*'
Last metadata expiration check: 0:06:20 ago on Tuesday 05 May 2020 03:38:28 PM EDT.
httpd-0:2.4.37-16.module_el8.1.0+256+ae790463.x86_64
httpd-devel-0:2.4.37-16.module_el8.1.0+256+ae790463.x86_64
httpd-filesystem-0:2.4.37-16.module_el8.1.0+256+ae790463.noarch
httpd-manual-0:2.4.37-16.module_el8.1.0+256+ae790463.noarch
httpd-tools-0:2.4.37-16.module_el8.1.0+256+ae790463.x86_64

4. Display source rpm of httpd package:

If we need find the source rpm of the package, use option –source

[root@server1 ~]# dnf repoquery --source httpd
Last metadata expiration check: 0:07:04 ago on Tuesday 05 May 2020 03:38:28 PM EDT.
httpd-2.4.37-16.module_el8.1.0+256+ae790463.src.rpm

5. Packages proving certain daemons

For example if we need to find the package that can be used as a webserver, using option “provides”

[root@server1 ~]# dnf repoquery --whatprovides webserver
Last metadata expiration check: 0:07:35 ago on Tuesday 05 May 2020 03:38:28 PM EDT.
httpd-0:2.4.37-16.module_el8.1.0+256+ae790463.x86_64
nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64

6. Display duplicate package

If we need to find the list of duplicate packages in the repo

[root@server1 ~]# dnf repoquery --duplicates
Last metadata expiration check: 0:08:47 ago on Tuesday 05 May 2020 03:38:28 PM EDT.

7. Query the file

In some scenarios we need to find from which package the file got created, for example we can try checking out /etc/httpd/conf/httpd.conf

[root@control ~]# dnf repoquery --file /etc/httpd/conf/httpd.conf
Last metadata expiration check: 0:02:48 ago on Wednesday 06 May 2020 01:20:27 AM IST.
httpd-0:2.4.37-16.module_el8.1.0+256+ae790463.x86_64
[root@control ~]#

9. dnf history

Whenever we make changes, all the changes will be recored in the dnf history, it will be helpful in case to find out what we changes we have done in recent times like we install/ remove/ upgrade packages.

[root@control ~]# dnf history
ID | Command line | Date and time | Action(s) | Altered

25 | install httpd | 2020-05-06 01:20 | Install | 6
24 | install bind-utils | 2020-05-06 00:36 | Install | 5
23 | remove bind-utils | 2020-05-06 00:35 | Removed | 5
22 | install bind-utils | 2020-05-06 00:35 | Install | 5
21 | install lsof | 2020-05-06 00:11 | Install | 1
20 | install -y tree | 2020-05-05 23:08 | Install | 1
19 | install sysstat | 2020-05-05 20:43 | Install | 2
18 | install git gcc gcc-c++ | 2020-04-23 21:46 | I, U | 7

1. Getting history information

Suppose we need to find out that we have done in the ID 25, we can execute the below command and find out the trasactions.

[root@control ~]# dnf history info 25
Transaction ID : 25
Begin time : Wednesday 06 May 2020 01:20:54 AM IST
Begin rpmdb : 885:b07222918328dbd229056240f7882670e23e0d30
End time : Wednesday 06 May 2020 01:20:57 AM IST (3 seconds)
End rpmdb : 891:c9b8c260eb7a08250e0604b07562443c10f38d65
User : DevOps
Return-Code : Success
Releasever : 8
Command Line : install httpd
Packages Altered:
Install centos-logos-httpd-80.5-2.el8.noarch @AppStream
Install httpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64 @AppStream
Install httpd-filesystem-2.4.37-16.module_el8.1.0+256+ae790463.noarch @AppStream
Install httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64 @AppStream
Install mod_http2-1.11.3-3.module_el8.1.0+213+acce2796.x86_64 @AppStream
Install mailcap-2.1.48-3.el8.noarch @BaseOS
[root@control ~]#

2. Revoking changes

In some scnerios we need to revert the changes what we done, we can easily able to do it with undo option

[root@control ~]# dnf history undo 24
Last metadata expiration check: 0:04:31 ago on Wednesday 06 May 2020 01:20:27 AM IST.
Undoing transaction 24, from Wednesday 06 May 2020 12:36:06 AM IST
Install bind-libs-32:9.11.4-26.P2.el8.x86_64 @AppStream
Install bind-libs-lite-32:9.11.4-26.P2.el8.x86_64 @AppStream
Install bind-license-32:9.11.4-26.P2.el8.noarch @AppStream
Install bind-utils-32:9.11.4-26.P2.el8.x86_64 @AppStream
Install python3-bind-32:9.11.4-26.P2.el8.noarch @AppStream
Dependencies resolved.
============================================================
Package Architecture Version Repository Size
============================================================

Removed:
bind-libs-32:9.11.4-26.P2.el8.x86_64 bind-libs-lite-32:9.11.4-26.P2.el8.x86_64 bind-license-32:9.11.4-26.P2.el8.noarch
bind-utils-32:9.11.4-26.P2.el8.x86_64 python3-bind-32:9.11.4-26.P2.el8.noarch
Complete!
[root@control ~]#

10. Removing a package

Removing a package use the below command, -y option will not ask for y to continue.

[root@control ~]# dnf remove httpd -y
Dependencies resolved.
============================================================
Package Architecture Version Repository Size
============================================================Removing:
httpd x86_64 2.4.37-16.module_el8.1.0+256+ae790463 @AppStream 5.4 M
Removed:
httpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64 centos-logos-httpd-80.5-2.el8.noarch
httpd-filesystem-2.4.37-16.module_el8.1.0+256+ae790463.noarch httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64
mailcap-2.1.48-3.el8.noarch mod_http2-1.11.3-3.module_el8.1.0+213+acce2796.x86_64
Complete!
[root@control ~]#

11. Update the package to lastest

dnf update command used to update the package to latest

dnf update

Using –exclude options, we can stop updating a particular package, in the previous example we could see java-1.8.0-openjdk and java-1.8.0-openjdk-headless are available for update.

[root@control ~]# dnf update --exclude=java-1.8.0-openjdk*
Last metadata expiration check: 0:09:33 ago on Wednesday 06 May 2020 01:20:27 AM IST.
Dependencies resolved.
============================================================
Package Architecture Version Repository Size
============================================================
Installing:
kernel x86_64 4.18.0-147.8.1.el8_1 BaseOS 1.5 M
kernel-core x86_64 4.18.0-147.8.1.el8_1 BaseOS 25 M
kernel-debug-devel x86_64 4.18.0-147.8.1.el8_1 BaseOS 14 M
kernel-devel x86_64 4.18.0-147.8.1.el8_1 BaseOS 13 M
kernel-modules x86_64 4.18.0-147.8.1.el8_1 BaseOS 22 M
Upgrading:
libluksmeta x86_64 9-3.el8_1.1 AppStream 27 k
luksmeta x86_64 9-3.el8_1.1 AppStream 23 k

Hope you have understood the how to use dnf basics, let us know your thoughts and share with us.

Also Refer yum package manager https://computercarriage.com/2020/05/31/easy-use-of-yum-package-manager/

One thought on “dnf Package manager utility RHEL / CentOS 8 / Fedora

Leave a Reply