The DNF (Dandified Yum) package manager is a powerful tool for managing software on Red Hat-based Linux distributions such as Rocky Linux, Fedora, and Red Hat Enterprise Linux (RHEL). In this post, we’ll explore how to download, install, update, and manage software packages using DNF, as well as how to enable and disable repositories and customize package management.
Finding Software Packages with DNF
The first step in managing software on your system is finding the right packages. DNF provides a simple and efficient way to search for software in your configured repositories. You can search for packages using the following command:
dnf search <package name>
[devops@server1 ~]$ dnf search nginx
Last metadata expiration check: 0:00:10 ago on Wed Aug 14 20:35:06 2024.
=============================== Name Exactly Matched: nginx ===============================
nginx.x86_64 : A high performance web server and reverse proxy server
============================== Name & Summary Matched: nginx ==============================
collectd-nginx.x86_64 : Nginx plugin for collectd
munin-nginx.noarch : NGINX support for Munin resource monitoring
nextcloud-nginx.noarch : Nginx integration for NextCloud
nginx-all-modules.noarch : A meta package that installs all available Nginx modules
nginx-core.x86_64 : nginx minimal core
nginx-filesystem.noarch : The basic directory layout for the Nginx server
nginx-mod-fancyindex.x86_64 : Nginx FancyIndex module
nginx-mod-http-image-filter.x86_64 : Nginx HTTP image filter module
nginx-mod-http-perl.x86_64 : Nginx HTTP perl module
nginx-mod-http-xslt-filter.x86_64 : Nginx XSLT module
nginx-mod-mail.x86_64 : Nginx mail modules
nginx-mod-modsecurity.x86_64 : ModSecurity v3 nginx connector
nginx-mod-stream.x86_64 : Nginx stream modules
nginx-mod-vts.x86_64 : Nginx virtual host traffic status module
pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx Webserver
python3-certbot-nginx.noarch : The nginx plugin for certbot
sympa-nginx.x86_64 : Sympa with nginx
This command will return a list of available packages that match the search term, along with a brief description of each package.
Getting Detailed Information About a Package
To get detailed information about a specific package, including its version, size, repository, and a more in-depth description, you can use the dnf info command:
dnf info <package name>
[devops@server1 ~]$ dnf info nginx
Last metadata expiration check: 0:01:23 ago on Wed Aug 14 20:35:06 2024.
Available Packages
Name : nginx
Epoch : 1
Version : 1.20.1
Release : 14.el9_2.1
Architecture : x86_64
Size : 36 k
Source : nginx-1.20.1-14.el9_2.1.src.rpm
Repository : appstream
Summary : A high performance web server and reverse proxy server
URL : https://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.
This command is useful for understanding more about what a package does and verifying that it meets your needs before installing it.
Finding Which Package Provides a Specific File
Sometimes, you may need to determine which package provides a specific file or command. This is where the dnf provides command comes in handy:
dnf provides <file_path_or_command>
[devops@server1 ~]$ dnf provides /var/www/html
Last metadata expiration check: 0:02:35 ago on Wed Aug 14 20:35:06 2024.
httpd-filesystem-2.4.57-11.el9_4.1.noarch : The basic directory layout for the Apache HTTP
: Server
Repo : appstream
Matched from:
Filename : /var/www/html
This command will list all packages that contain the specified file or command, which can be particularly useful for troubleshooting dependencies.
Installing Software Packages with DNF
Once you’ve identified the package you want to install, DNF makes the installation process straightforward. To install a package, use the following command:
sudo dnf install <package_name>
[devops@server1 ~]$ sudo dnf install nginx
Last metadata expiration check: 0:00:05 ago on Wed Aug 14 20:40:41 2024.
Dependencies resolved.
===========================================================================================
Package Architecture Version Repository Size
===========================================================================================
Installing:
nginx x86_64 1:1.20.1-14.el9_2.1 appstream 36 k
Installing dependencies:
nginx-core x86_64 1:1.20.1-14.el9_2.1 appstream 565 k
nginx-filesystem noarch 1:1.20.1-14.el9_2.1 appstream 8.5 k
rocky-logos-httpd noarch 90.15-2.el9 appstream 24 k
Transaction Summary
===========================================================================================
Install 4 Packages
Total download size: 634 k
Installed size: 1.8 M
Is this ok [y/N]:
DNF will resolve any dependencies required by the package and prompt you to confirm the installation. After confirming, DNF will download and install the package along with its dependencies.
Listing Available Package Groups
In addition to managing individual packages, DNF also allows you to manage groups of related packages. This is especially useful when you need to install a complete environment or set of tools. To see a list of available package groups, use:
[devops@server1 ~]$ dnf group list
Last metadata expiration check: 0:20:32 ago on Wed Aug 14 20:35:06 2024.
Available Environment Groups:
Server with GUI
Server
Workstation
KDE Plasma Workspaces
Custom Operating System
Installed Environment Groups:
Minimal Install
Virtualization Host
Installed Groups:
Container Management
Development Tools
Security Tools
Available Groups:
Fedora Packager
VideoLAN Client
Xfce
Legacy UNIX Compatibility
Console Internet Tools
.NET Development
Graphical Administration Tools
Headless Management
Network Servers
RPM Development Tools
Scientific Support
Smart Card Support
System Tools
This command will display a list of available groups, installed groups, and groups that are partially installed. Package groups often represent a collection of packages needed for a specific role, such as a “Development Tools” group.
Installing a Package Group
To install a complete group of packages, you can use the dnf group install command followed by the name of the group. For example, to install the “Development Tools” group, you would run:
[devops@server1 ~]$ sudo dnf group install "Development Tools"
Last metadata expiration check: 0:14:53 ago on Wed Aug 14 20:42:56 2024.
Dependencies resolved.
=====================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================
Installing Groups:
Development Tools
Transaction Summary
=====================================================================================================================
Is this ok [y/N]:
This command will install all the packages that are part of the “Development Tools” group, providing you with a ready-to-use development environment.
Updating Software Packages with DNF
Keeping your system up to date is crucial for security and stability. DNF makes it easy to update individual packages or your entire system. To update a specific package, use:
sudo dnf update <package_name>
# to update the "nginx".
sudo dnf update nginx
# To update all installed packages on your system
sudo dnf update
Enabling and Disabling DNF Software Repositories
DNF relies on repositories, which are collections of software packages stored on remote servers. By default, your system is configured to use certain repositories, but you may want to enable or disable additional repositories as needed.
To enable or disable a repository, you can use the following commands:
# Enable epel repository.
[devops@server1 ~]$ sudo dnf config-manager --set-enabled epel
# Disable epel repository.
[devops@server1 ~]$ sudo dnf config-manager --set-disabled epel
Listing Enabled Repositories
To see a list of all currently enabled repositories, you can use:
[devops@server1 ~]$ dnf repolist
repo id repo name
appstream Rocky Linux 9 - AppStream
baseos Rocky Linux 9 - BaseOS
epel Extra Packages for Enterprise Linux 9 - x86_64
epel-cisco-openh264 Extra Packages for Enterprise Linux 9 openh264 (From Cisco) - x86_64
extras Rocky Linux 9 - Extras
This command will display the IDs and names of all repositories that DNF is currently using.
Uninstalling Software Packages with DNF
If you need to uninstall a package, DNF provides a simple way to do so. To remove a specific package, use the following command:
sudo dnf remove <package_name>
[devops@server1 ~]$ sudo dnf remove vim
Dependencies resolved.
=====================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================
Removing:
vim-enhanced x86_64 2:8.2.2637-20.el9_1 @appstream 3.8 M
Removing unused dependencies:
gpm-libs x86_64 1.20.7-29.el9 @appstream 28 k
vim-common x86_64 2:8.2.2637-20.el9_1 @appstream 30 M
Transaction Summary
=====================================================================================================================
Remove 3 Packages
Freed space: 34 M
Is this ok [y/N]:
This command will uninstall the package and remove any dependencies that are no longer needed by other installed software.
Cleaning Up Unused Packages
Over time, your system may accumulate unnecessary packages. DNF provides tools to clean up these packages and free up disk space. To remove packages that are no longer required by any installed software:
[devops@server1 ~]$ sudo dnf autoremove
Last metadata expiration check: 0:31:50 ago on Wed Aug 14 20:42:56 2024.
Dependencies resolved.
=====================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================
Removing:
grub2-tools-efi x86_64 1:2.06-80.el9_4 @baseos 2.7 M
grub2-tools-extra x86_64 1:2.06-80.el9_4 @baseos 5.3 M
mesa-vulkan-drivers x86_64 23.3.3-1.el9 @appstream 46 M
pulseaudio-utils x86_64 15.0-2.el9 @appstream 199 k
vulkan-loader x86_64 1.3.268.0-1.el9 @appstream 492 k
Transaction Summary
=====================================================================================================================
Remove 5 Packages
Freed space: 55 M
Is this ok [y/N]:
You can also clear DNF’s cache, which stores downloaded packages and metadata:
[devops@server1 ~]$ sudo dnf clean all
783 files removed
This command will remove cached data, which can be useful if you want to force DNF to download fresh metadata and packages.
Removing a Package Group
If you no longer need a group of packages, you can remove it using the dnf group remove command:
[devops@server1 ~]$ sudo dnf group remove "Development Tools"
Dependencies resolved.
=====================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================
Removing:
asciidoc noarch 9.1.0-3.el9 @appstream 949 k
autoconf noarch 2.69-38.el9 @appstream 2.2 M
automake noarch 1.16.2-8.el9 @appstream 1.7 M
byacc x86_64 2.0.20210109-4.el9 @appstream 271 k
diffstat x86_64 1.64-6.el9 @appstream 76 k
gcc-c++ x86_64 11.4.1-3.el9 @appstream 32 M
gdb x86_64 10.2-13.el9 @appstream 388 k
git x86_64 2.43.5-1.el9_4 @appstream 86 k
intltool noarch 0.51.0-20.el9 @appstream 169 k
jna x86_64 5.6.0-8.el9 @appstream 459 k
libtool x86_64 2.4.6-45.el9 @appstream 2.6 M
ltrace x86_64 0.7.91-43.el9 @appstream 309 k
patchutils x86_64 0.4.2-7.el9 @appstream 210 k
perl-Fedora-VSP noarch 0.001-23.el9 @appstream 40 k
perl-generators noarch 1.11-12.el9 @appstream 21 k
pesign x86_64 115-6.el9_1.rocky.2 @appstream 809 k
redhat-rpm-config noarch 207-1.el9 @appstream 187 k
rpm-build x86_64 4.16.1.3-29.el9 @appstream 146 k
rpm-sign x86_64 4.16.1.3-29.el9 @baseos 22 k
source-highlight x86_64 3.1.9-11.el9 @appstream 2.8 M
systemtap x86_64 5.0-4.el9 @appstream 0
valgrind x86_64 1:3.22.0-2.el9 @appstream 29 M
valgrind-devel x86_64 1:3.22.0-2.el9 @appstream 502 k
Removing unused dependencies:
annobin x86_64 12.31-2.el9 @appstream 1.1 M
boost-filesystem x86_64 1.75.0-8.el9 @appstream 124 k
boost-regex x86_64 1.75.0-8.el9 @appstream 868 k
copy-jdk-configs noarch 4.0-3.el9 @appstream 19 k
debugedit x86_64 5.0-5.el9 @appstream 189 k
docbook-dtds noarch 1.0-79.el9 @appstream 8.3 M
docbook-style-xsl noarch 1.79.2-16.el9 @appstream 16 M
dwz x86_64 0.14-3.el9 @appstream 275 k
dyninst x86_64 12.1.0-1.el9 @appstream 14 M
ed x86_64 1.14.2-12.el9 @baseos 127 k
efi-srpm-macros noarch 6-2.el9_0 @appstream 40 k
efivar-libs x86_64 38-3.el9 @baseos 367 k
elfutils x86_64 0.190-2.el9 @baseos 2.8 M
elfutils-devel x86_64 0.190-2.el9 @appstream 174 k
fonts-srpm-macros noarch 1:2.0.5-7.el9.1 @appstream 55 k
gcc-plugin-annobin x86_64 11.4.1-3.el9 @appstream 52 k
gdb-headless x86_64 10.2-13.el9 @appstream 12 M
gettext-common-devel noarch 0.21-8.el9 @appstream 398 k
gettext-devel x86_64 0.21-8.el9 @appstream 849 k
ghc-srpm-macros noarch 1.5.0-6.el9 @appstream 535
git-core-doc noarch 2.43.5-1.el9_4 @appstream 17 M
go-srpm-macros noarch 3.2.0-3.el9 @appstream 60 k
info x86_64 6.7-15.el9 @baseos 496 k
java-1.8.0-openjdk-headless x86_64 1:1.8.0.422.b05-2.el9 @appstream 113 M
javapackages-filesystem noarch 6.0.0-4.el9 @appstream 1.9 k
kernel-srpm-macros noarch 1.0-13.el9 @appstream 17 k
libbabeltrace x86_64 1.5.8-10.el9 @appstream 517 k
libipt x86_64 2.0.4-5.el9 @appstream 115 k
libstdc++-devel x86_64 11.4.1-3.el9 @appstream 13 M
lksctp-tools x86_64 1.0.19-3.el9_4 @baseos 269 k
lua x86_64 5.4.4-4.el9 @appstream 593 k
lua-posix x86_64 35.0-8.el9 @appstream 614 k
lua-srpm-macros noarch 1-6.el9 @appstream 1.3 k
mokutil x86_64 2:0.6.0-4.el9 @baseos 98 k
nss-tools x86_64 3.90.0-7.el9_4 @appstream 1.3 M
ocaml-srpm-macros noarch 6-6.el9 @appstream 745
openblas-srpm-macros noarch 2-11.el9 @appstream 104
patch x86_64 2.7.6-16.el9 @appstream 259 k
perl-Error noarch 1:0.17029-7.el9 @appstream 78 k
perl-File-Compare noarch 1.100.600-481.el9 @appstream 6.5 k
perl-File-Copy noarch 2.34-481.el9 @appstream 21 k
perl-File-Find noarch 1.37-481.el9 @appstream 39 k
perl-Git noarch 2.43.5-1.el9_4 @appstream 65 k
perl-TermReadKey x86_64 2.38-11.el9 @appstream 65 k
perl-Thread-Queue noarch 3.14-460.el9 @appstream 29 k
perl-XML-Parser x86_64 2.46-9.el9 @appstream 655 k
perl-lib x86_64 0.65-481.el9 @appstream 9.4 k
perl-macros noarch 4:5.32.1-481.el9 @appstream 5.5 k
perl-srpm-macros noarch 1-41.el9 @appstream 862
perl-threads x86_64 1:2.25-460.el9 @appstream 112 k
perl-threads-shared x86_64 1.61-460.el9.0.1 @appstream 80 k
perl-version x86_64 7:0.99.28-4.el9 @appstream 129 k
pyproject-srpm-macros noarch 1.12.0-1.el9 @appstream 1.5 k
python-srpm-macros noarch 3.9-53.el9 @appstream 36 k
qt5-srpm-macros noarch 5.15.9-1.el9 @appstream 492
rust-srpm-macros noarch 17-4.el9 @appstream 2.4 k
sgml-common noarch 0.6.3-58.el9 @appstream 168 k
systemtap-client x86_64 5.0-4.el9 @appstream 11 M
systemtap-devel x86_64 5.0-4.el9 @appstream 9.6 M
systemtap-runtime x86_64 5.0-4.el9 @appstream 1.0 M
tbb x86_64 2020.3-8.el9 @appstream 489 k
tzdata-java noarch 2024a-1.el9 @appstream 342 k
unzip x86_64 6.0-56.el9 @baseos 392 k
xz-devel x86_64 5.2.5-8.el9_0 @appstream 202 k
zip x86_64 3.0-35.el9 @baseos 724 k
Removing Groups:
Development Tools
Transaction Summary
=====================================================================================================================
Remove 88 Packages
Freed space: 305 M
Is this ok [y/N]:
This will uninstall all the packages that were part of the group, helping you to keep your system clean and free of unnecessary software.
Configuring DNF and Package Management
DNF’s behavior can be customized by editing its configuration file, located at /etc/dnf/dnf.conf. For example, you can adjust the number of parallel downloads, enable or disable package caching, and set the fastest mirror detection.
- fastestmirror=1: Enable this option to automatically select the fastest mirror for downloading packages.
- max_parallel_downloads=10: Increase the number of parallel downloads to speed up package installations.
vim /etc/dnf/dnf.conf
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False
fastestmirror=1
max_parallel_downloads=10
DNF is a powerful and flexible package manager that makes it easy to manage software on Rocky Linux, Fedora, and Red Hat Enterprise Linux. With commands like dnf search, dnf info, dnf provides, and dnf group list, you can efficiently find, install, update, and remove software packages and groups. Additionally, by mastering repository management and customizing DNF settings, you can optimize your system for performance and security. Whether you’re installing software, updating packages, or cleaning up your system, DNF provides the tools you need to keep your Linux distribution running smoothly.