RED HAT ENTERPRISE LINUX

DNF Package Management

Download, Install, Update, and Manage Software

CIS126RH | RHEL System Administration 1
Mesa Community College

Learning Objectives

1
Understand packages and repositories

RPM packages, dependencies, and Red Hat repositories

Search and query packages

Find packages, view information, and check what is installed

3
Install and remove software

Install packages, package groups, and remove software safely

4
Update and maintain systems

Apply updates, security patches, and manage package history

5
Configure repositories

Enable, disable, and add software repositories

What is a Package?

A package is an archive containing software files, metadata, and installation scripts. In RHEL, packages use the RPM (Red Hat Package Manager) format.

httpd-2.4.57-5.el9.x86_64.rpm

name   version release dist  arch
Package contains:
  • Binary executables
  • Configuration files
  • Documentation
  • Dependencies list
  • Install/uninstall scripts
Common architectures:
  • x86_64 - 64-bit Intel/AMD
  • aarch64 - 64-bit ARM
  • noarch - Architecture independent
  • i686 - 32-bit (legacy)

What is a Repository?

A repository (repo) is a collection of packages stored on a server. DNF downloads packages from configured repositories, handling dependencies automatically.

Red Hat Repos
DNF
Your System
# List enabled repositories
[root@host ~]# dnf repolist
repo id                              repo name
rhel-9-for-x86_64-baseos-rpms        Red Hat Enterprise Linux 9 - BaseOS
rhel-9-for-x86_64-appstream-rpms     Red Hat Enterprise Linux 9 - AppStream

# List all repositories (including disabled)
[root@host ~]# dnf repolist all
Red Hat repositories require subscription. Your system must be registered with subscription-manager to access official packages.

DNF vs YUM

DNF (Dandified YUM) replaced YUM as the default package manager in RHEL 8. It offers better performance, improved dependency resolution, and a cleaner codebase.

FeatureDNF (RHEL 8/9)YUM (RHEL 7)
PerformanceFaster, parallel downloadsSlower, sequential
DependenciesBetter resolution algorithmOlder algorithm
Memory usageMore efficientHigher usage
APIClean Python APILegacy API
ModularityFull supportNot supported
# yum command still works (it's an alias to dnf)
[root@host ~]# yum install httpd
# Same as:
[root@host ~]# dnf install httpd

# Check which is actually running
[root@host ~]# ls -la /usr/bin/yum
lrwxrwxrwx. 1 root root 5 ... /usr/bin/yum -> dnf-3

Searching for Packages

# Search for packages by keyword
[root@host ~]# dnf search web server
========================= Name Matched: web server =========================
httpd.x86_64 : Apache HTTP Server
nginx.x86_64 : A high performance web server and reverse proxy server

# Search only in package names
[root@host ~]# dnf search --name-only httpd

# Find which package provides a file
[root@host ~]# dnf provides /usr/bin/vim
vim-enhanced-2:9.0.1712-1.el9.x86_64 : A version of the VIM editor
Repo        : rhel-9-for-x86_64-appstream-rpms
Matched from:
Filename    : /usr/bin/vim

# Find package providing a command (using wildcards)
[root@host ~]# dnf provides */sshd
openssh-server-8.7p1-34.el9.x86_64 : An open source SSH server daemon

Package Information

# View detailed package information
[root@host ~]# dnf info httpd
Name         : httpd
Version      : 2.4.57
Release      : 5.el9
Architecture : x86_64
Size         : 59 k
Source       : httpd-2.4.57-5.el9.src.rpm
Repository   : rhel-9-for-x86_64-appstream-rpms
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.

# List all packages (installed and available)
[root@host ~]# dnf list all

# List only installed packages
[root@host ~]# dnf list installed

# List available packages (not installed)
[root@host ~]# dnf list available

# Check if specific package is installed
[root@host ~]# dnf list installed httpd

Installing Packages

dnf install downloads and installs packages along with all required dependencies. It shows what will be installed and asks for confirmation.

# Install a single package
[root@host ~]# dnf install httpd
Dependencies resolved.
================================================================================
 Package              Arch       Version              Repository          Size
================================================================================
Installing:
 httpd                x86_64     2.4.57-5.el9         appstream           59 k
Installing dependencies:
 apr                  x86_64     1.7.0-11.el9         appstream          127 k
 apr-util             x86_64     1.6.1-23.el9         appstream          105 k
 httpd-core           x86_64     2.4.57-5.el9         appstream          1.4 M
 httpd-filesystem     noarch     2.4.57-5.el9         appstream           17 k
 httpd-tools          x86_64     2.4.57-5.el9         appstream           82 k
 mod_http2            x86_64     2.0.26-1.el9         appstream          172 k
...
Transaction Summary
================================================================================
Install  9 Packages

Total download size: 2.1 M
Installed size: 5.8 M
Is this ok [y/N]: y

Installing Multiple Packages

# Install multiple packages at once
[root@host ~]# dnf install httpd mariadb-server php

# Install without confirmation prompt (-y flag)
[root@host ~]# dnf install -y vim-enhanced

# Install specific version
[root@host ~]# dnf install httpd-2.4.57-5.el9

# Install from local RPM file
[root@host ~]# dnf install ./package.rpm

# Reinstall a package (replaces existing)
[root@host ~]# dnf reinstall httpd

# Download without installing
[root@host ~]# dnf download httpd
httpd-2.4.57-5.el9.x86_64.rpm
Caution: The -y flag skips confirmation. Use carefully - always review what DNF plans to do in production.

Package Groups

Package groups bundle related packages together. Install a group to get a complete set of tools for a specific purpose.

# List available groups
[root@host ~]# dnf group list
Available Environment Groups:
   Server with GUI
   Server
   Minimal Install
   Workstation
Available Groups:
   Development Tools
   Headless Management
   Network Servers
   System Tools

# View group contents
[root@host ~]# dnf group info "Development Tools"
Group: Development Tools
 Mandatory Packages:
   gcc
   make
   autoconf
   automake
 Optional Packages:
   valgrind
   cmake

# Install a group
[root@host ~]# dnf group install "Development Tools"

Removing Packages

dnf remove uninstalls packages. DNF also removes packages that depend on what you are removing - review carefully!

# Remove a package
[root@host ~]# dnf remove httpd
Dependencies resolved.
================================================================================
 Package              Arch       Version              Repository          Size
================================================================================
Removing:
 httpd                x86_64     2.4.57-5.el9         @appstream          59 k
Removing dependent packages:
 mod_ssl              x86_64     1:2.4.57-5.el9       @appstream         151 k
Removing unused dependencies:
 apr                  x86_64     1.7.0-11.el9         @appstream         290 k
 apr-util             x86_64     1.6.1-23.el9         @appstream         220 k

Transaction Summary
================================================================================
Remove  4 Packages

Is this ok [y/N]:

# Remove without removing unused dependencies
[root@host ~]# dnf remove --noautoremove httpd
Warning: Removing packages can break dependent software. Always review the removal list before confirming!

Updating Packages

dnf update (or upgrade) downloads and installs newer versions of installed packages. Critical for security patches!

# Check for available updates
[root@host ~]# dnf check-update
kernel.x86_64                   5.14.0-362.18.1.el9      baseos
openssl.x86_64                  1:3.0.7-25.el9           baseos
vim-enhanced.x86_64             2:9.0.2081-1.el9         appstream

# Update all packages
[root@host ~]# dnf update
# or equivalently:
[root@host ~]# dnf upgrade

# Update specific package only
[root@host ~]# dnf update openssl

# Update with security fixes only
[root@host ~]# dnf update --security

# See what security updates are available
[root@host ~]# dnf updateinfo list security
Best practice: Regularly run dnf update to keep systems patched against security vulnerabilities.

Managing History

DNF keeps a transaction history. You can review past operations and undo changes if needed.

# View transaction history
[root@host ~]# dnf history
ID  | Command               | Date and time    | Action(s) | Altered
--------------------------------------------------------------------
 15 | update                | 2024-01-20 10:30 | Upgrade   |   23
 14 | install httpd         | 2024-01-19 14:22 | Install   |    9
 13 | remove vim-enhanced   | 2024-01-18 09:15 | Removed   |    1

# View details of specific transaction
[root@host ~]# dnf history info 14
Transaction ID : 14
Begin time     : Fri 19 Jan 2024 02:22:15 PM
Packages Altered:
    Install httpd-2.4.57-5.el9.x86_64  @appstream
    Install apr-1.7.0-11.el9.x86_64    @appstream
    ...

# Undo a transaction (reverse the changes)
[root@host ~]# dnf history undo 14

# Redo a transaction (repeat it)
[root@host ~]# dnf history redo 14

Working with Repositories

# List all repos (enabled and disabled)
[root@host ~]# dnf repolist all
repo id                              status
rhel-9-for-x86_64-baseos-rpms        enabled
rhel-9-for-x86_64-appstream-rpms     enabled
codeready-builder-for-rhel-9         disabled

# Enable a repository
[root@host ~]# dnf config-manager --enable codeready-builder-for-rhel-9

# Disable a repository
[root@host ~]# dnf config-manager --disable codeready-builder-for-rhel-9

# Temporarily use a disabled repo for one command
[root@host ~]# dnf install package --enablerepo=codeready-builder-for-rhel-9

# Temporarily disable a repo for one command
[root@host ~]# dnf update --disablerepo=epel

# View repository details
[root@host ~]# dnf repoinfo rhel-9-for-x86_64-baseos-rpms

Repository Configuration

Repository definitions are stored in /etc/yum.repos.d/ as .repo files. Each file can define one or more repositories.

# List repository configuration files
[root@host ~]# ls /etc/yum.repos.d/
redhat.repo

# Repository file structure
[root@host ~]# cat /etc/yum.repos.d/example.repo
[example-repo]
name=Example Repository
baseurl=https://repo.example.com/rhel9/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example

# Key fields:
# [repo-id]     - Unique identifier
# name          - Human-readable name
# baseurl       - URL to repository
# enabled       - 1=enabled, 0=disabled
# gpgcheck      - 1=verify signatures, 0=don't
# gpgkey        - GPG key for verification
Security: Always enable gpgcheck=1 for production systems. This verifies packages are signed and unmodified.

Adding Third-Party Repos

# Example: Adding EPEL (Extra Packages for Enterprise Linux)
[root@host ~]# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

# This installs the EPEL repository configuration and GPG key
[root@host ~]# dnf repolist
repo id                              repo name
epel                                 Extra Packages for Enterprise Linux 9
rhel-9-for-x86_64-baseos-rpms        Red Hat Enterprise Linux 9 - BaseOS
rhel-9-for-x86_64-appstream-rpms     Red Hat Enterprise Linux 9 - AppStream

# Now you can install packages from EPEL
[root@host ~]# dnf install htop

# Add repository using config-manager
[root@host ~]# dnf config-manager --add-repo https://example.com/repo.repo
Warning: Third-party packages are not supported by Red Hat. Use them carefully, especially in production environments.

Application Streams

Application Streams allow multiple versions of software to coexist in repositories. Choose the version that fits your needs.

# List available modules
[root@host ~]# dnf module list
Name      Stream    Profiles             Summary
nodejs    18        common, development  Javascript runtime
nodejs    20        common, development  Javascript runtime
php       8.1       common, devel        PHP scripting language
php       8.2       common, devel        PHP scripting language
ruby      3.1       common               Ruby programming language
ruby      3.3       common               Ruby programming language

# View module details
[root@host ~]# dnf module info php:8.2

# Enable a specific stream
[root@host ~]# dnf module enable php:8.2

# Install module with default profile
[root@host ~]# dnf module install php:8.2

# Switch to different stream (reset first)
[root@host ~]# dnf module reset php
[root@host ~]# dnf module enable php:8.1

DNF Cache and Cleanup

# DNF caches repository metadata and downloaded packages
# View cache information
[root@host ~]# dnf repoinfo

# Clean cached metadata (forces refresh on next run)
[root@host ~]# dnf clean metadata

# Clean cached packages (downloaded RPMs)
[root@host ~]# dnf clean packages

# Clean everything
[root@host ~]# dnf clean all

# Force metadata refresh
[root@host ~]# dnf makecache

# Remove packages that are no longer needed (orphaned dependencies)
[root@host ~]# dnf autoremove

# Check cache location
[root@host ~]# ls /var/cache/dnf/
Tip: If you see stale package lists or repository errors, try dnf clean all followed by your command.

Troubleshooting DNF

# Dependency problems - check what's broken
[root@host ~]# dnf check

# Force reinstall to fix corrupted package
[root@host ~]# dnf reinstall httpd

# View RPM database problems
[root@host ~]# rpm --rebuilddb

# Verbose output for debugging
[root@host ~]# dnf -v install httpd

# Check package file integrity
[root@host ~]# rpm -V httpd
S.5....T.  c /etc/httpd/conf/httpd.conf
# Shows modified config file (expected for configs)

# See which package owns a file
[root@host ~]# rpm -qf /etc/passwd
setup-2.13.7-9.el9.noarch
Common issues: Network problems (check connectivity), stale cache (dnf clean all), subscription issues (subscription-manager status), disk space (df -h).

Best Practices

Do

  • Review transactions before confirming
  • Keep systems updated regularly
  • Test updates in non-production first
  • Use GPG verification for packages
  • Document repository changes
  • Maintain valid subscriptions
  • Use dnf history for rollbacks
  • Clean cache when troubleshooting

Do Not

  • Use -y blindly in production
  • Disable GPG checking
  • Add untrusted repositories
  • Ignore dependency removal warnings
  • Skip reading transaction summaries
  • Mix packages from incompatible repos
  • Force install with --nodeps
  • Delay security updates
Golden rule: Read what DNF tells you. The transaction summary and warnings exist to prevent mistakes.

Key Takeaways

1

Repositories: Collections of packages. RHEL uses BaseOS, AppStream, and CodeReady Builder. Enable with dnf config-manager.

Search: dnf search finds packages. dnf provides finds packages containing files. dnf info shows details.

3

Install: dnf install adds packages with dependencies. dnf group install installs package groups.

4

Update: dnf update applies updates. dnf history tracks and reverses changes.

5

Remove: dnf remove uninstalls. Watch for dependent package removal!

Next: Managing Services with systemd

Graded Lab

  • Search for and install a web server package
  • View package information before and after installation
  • Install the "Development Tools" group
  • Check for and apply available updates
  • View transaction history and practice undo
  • Enable the CodeReady Builder repository

Next: Installing and Updating Applications by Using Flatpak