Install and Update
Software Packages

Install and update software packages from Red Hat CDN, a remote repository, or from the local file system

CIS126RH | RHEL System Administration 1
Mesa Community College

RHEL 9 uses DNF (Dandified YUM) as its package manager for installing, updating, and removing RPM packages with automatic dependency resolution. Packages can come from the Red Hat Content Delivery Network (CDN), third-party or custom repositories, or directly from local .rpm files. All three installation sources and their configuration are tested on the RHCSA exam.

Learning Objectives

  1. Use DNF to search, install, update, and remove packages — Execute the core DNF commands for package lifecycle management from configured repositories
  2. Configure access to a remote repository — Create a .repo file in /etc/yum.repos.d/ to add a third-party or custom repository as a package source
  3. Install packages from the local file system — Use dnf install and rpm to install .rpm files directly without a network repository
  4. Inspect packages and manage package history — Use dnf info, rpm -q, and dnf history to query package state and undo transactions

RPM and DNF: The Package System

RHEL software is distributed as RPM packages — compressed archives containing files, metadata, and installation scripts. DNF manages these packages with automatic dependency resolution.

  • RPM — the low-level package format and tool; installs individual .rpm files but does not resolve dependencies automatically
  • DNF — the high-level package manager that downloads packages from repositories and automatically installs all required dependencies
  • An RPM package name includes name, version, release, architecture: httpd-2.4.57-11.el9.x86_64.rpm
  • A repository is a collection of RPM packages with metadata that allows DNF to search, download, and verify packages
DNF replaced YUM in RHEL 8+

DNF (Dandified YUM) is the successor to YUM. On RHEL 9, the yum command is a compatibility alias for dnf — both run the same code. DNF is faster, uses less memory, and has better dependency resolution.

Core DNF Commands: Search and Info

# Search for packages by name or description keyword
$ dnf search httpd
================== Name Exactly Matched: httpd ==================
httpd.x86_64 : The Apache HTTP Server

# Search all fields (name, summary, description)
$ dnf search all web server

# Show detailed information about a package
$ dnf info httpd
Name         : httpd
Version      : 2.4.57
Release      : 11.el9
Architecture : x86_64
Repository   : appstream
Summary      : The Apache HTTP Server

# Find what package provides a specific command or file
$ dnf provides /usr/bin/nmap
$ dnf provides httpd

# List all installed packages
$ dnf list installed

# List packages available in a specific repo
$ dnf list available --repo appstream

Core DNF Commands: Install, Update, Remove

# Install a package (and all dependencies)
$ sudo dnf install -y httpd
$ sudo dnf install -y httpd mod_ssl   # multiple packages

# Update a specific package
$ sudo dnf update -y httpd

# Update all installed packages
$ sudo dnf update -y

# Remove a package
$ sudo dnf remove httpd

# Remove package and unused dependencies
$ sudo dnf autoremove httpd

# Check what updates are available without installing
$ dnf check-update
Use -y on the exam for speed

The -y flag automatically answers "yes" to all prompts. Use dnf install -y PACKAGE and dnf update -y to avoid waiting for confirmation during the exam.

Repositories: How DNF Finds Packages

A repository is a server (or local directory) that provides RPM packages with signed metadata. DNF reads repository configuration from /etc/yum.repos.d/.

# List all configured and enabled repositories
$ dnf repolist
repo id                  repo name
appstream                Red Hat Enterprise Linux 9 for x86_64 - AppStream
baseos                   Red Hat Enterprise Linux 9 for x86_64 - BaseOS

# List all repos including disabled
$ dnf repolist all

# Show detailed info about a repo
$ dnf repoinfo appstream

# Repository configuration files location
$ ls /etc/yum.repos.d/
redhat.repo   classroom.repo   epel.repo
RHEL 9 default repositories

BaseOS — core OS packages (kernel, glibc, systemd) — stable across RHEL lifecycle.
AppStream — application software (httpd, mariadb, python3) — updated frequently.
Both require a valid Red Hat subscription or a lab content source.

Configuring a Repository: The .repo File

To use a repository, create a .repo file in /etc/yum.repos.d/. Each file can define one or more repositories.

# Create a new repository configuration file
$ sudo vim /etc/yum.repos.d/classroom.repo

# OR create with tee (useful for scripting)
$ sudo tee /etc/yum.repos.d/classroom.repo <<'EOF'
[classroom-baseos]
name=Classroom BaseOS
baseurl=http://classroom.example.com/rhel9/baseos
enabled=1
gpgcheck=0

[classroom-appstream]
name=Classroom AppStream
baseurl=http://classroom.example.com/rhel9/appstream
enabled=1
gpgcheck=0
EOF

# Verify the new repositories are available
$ dnf repolist
classroom-baseos         Classroom BaseOS
classroom-appstream      Classroom AppStream
RHCSA exam pattern for repository configuration

The exam gives you a URL and asks you to configure a repo. Create a .repo file with [id], name=, baseurl=, enabled=1, and gpgcheck=0 (or gpgkey=). Verify with dnf repolist.

.repo File: All Key Options

Option Required? Description
[repoid]YesSection header — unique ID, no spaces. E.g. [classroom-baseos]
name=YesHuman-readable label shown in dnf repolist
baseurl=Yes*URL to repo root: http://, ftp://, or file:///path
mirrorlist=Yes*URL to a list of mirror URLs (alternative to baseurl)
enabled=No (default 1)1 = use this repo; 0 = skip this repo
gpgcheck=No (default 1)1 = verify package GPG signatures; 0 = skip verification
gpgkey=If gpgcheck=1URL or local path to the GPG public key file
sslverify=No (default 1)0 = skip SSL verification for HTTPS repos
gpgcheck=0 is a security risk

Only use gpgcheck=0 in trusted lab environments. In production, always set gpgcheck=1 and provide the correct gpgkey= URL to verify package authenticity.

Adding Repos with dnf config-manager

The dnf config-manager plugin adds and manages repositories without manually editing files.

# Install the plugin if needed
$ sudo dnf install -y dnf-plugins-core

# Add a repository from a URL
$ sudo dnf config-manager --add-repo \
    http://classroom.example.com/rhel9/baseos
# Creates a .repo file in /etc/yum.repos.d/ automatically

# Permanently enable or disable a repo by ID
$ sudo dnf config-manager --enable epel
$ sudo dnf config-manager --disable epel

# Use a specific repo for just one transaction
$ sudo dnf install --enablerepo=classroom-appstream httpd

# Disable a repo for just one transaction
$ sudo dnf install --disablerepo=appstream httpd

Installing from Local .rpm Files

When a package is not in a repository, install directly from a downloaded .rpm file.

Preferred: dnf install with the file path

# Install a local .rpm — dnf resolves dependencies from configured repos
$ sudo dnf install -y /tmp/mypackage-1.0-1.el9.x86_64.rpm
$ sudo dnf localinstall -y /tmp/mypackage-1.0-1.el9.x86_64.rpm
# localinstall is an alias for install — same behaviour

Alternative: rpm -ivh (no dependency resolution)

# Install with rpm — fails if dependencies are missing
$ sudo rpm -ivh /tmp/mypackage-1.0-1.el9.x86_64.rpm
# -i = install, -v = verbose, -h = hash progress

# Upgrade with rpm
$ sudo rpm -Uvh /tmp/mypackage-1.1-1.el9.x86_64.rpm

# rpm fails with missing dependencies:
error: Failed dependencies:
    libfoo.so.1 is needed by mypackage-1.0-1.el9.x86_64
Prefer dnf install for local .rpm files

Use sudo dnf install -y /path/to/file.rpm — DNF automatically fetches missing dependencies from configured repositories. Use rpm -ivh only when no repositories are available.

Querying Packages: rpm -q

The rpm -q family queries the local RPM database about installed packages — no network access required.

# Check if a package is installed
$ rpm -q httpd
httpd-2.4.57-11.el9.x86_64

$ rpm -q nginx
package nginx is not installed

# List all files installed by a package
$ rpm -ql httpd
/etc/httpd/conf/httpd.conf
/usr/sbin/httpd
...

# Find which package owns a specific file
$ rpm -qf /usr/sbin/httpd
httpd-2.4.57-11.el9.x86_64

# Show full package info (like dnf info but offline)
$ rpm -qi httpd

# Show only config files for a package
$ rpm -qc httpd

# Show documentation files for a package
$ rpm -qd httpd

DNF History and Transaction Rollback

DNF records every install, update, and remove operation, allowing review and rollback of past transactions.

# Show the transaction history
$ dnf history
ID  | Command line         | Date and time       | Action(s)  | Altered
-----------------------------------------------------------------------
 12 | install -y httpd     | 2026-05-25 10:00    | Install    |    5
 11 | update               | 2026-05-24 08:00    | Update     |   23

# Show details of a specific transaction
$ dnf history info 12

# Undo a transaction (if it was an install → removes the packages)
$ sudo dnf history undo 12

# Redo a previously undone transaction
$ sudo dnf history redo 12
history undo reverses a specific transaction

If transaction 12 installed packages, dnf history undo 12 removes them. If it removed packages, undo reinstalls them. This is the safest way to reverse an accidental install or remove.

DNF Package Groups

Package groups bundle related packages for common use cases.

# List all available package groups
$ dnf group list
Available Environment Groups:
   Server
   Minimal Install
Available Groups:
   Development Tools
   Security Tools

# Show what packages are in a group
$ dnf group info "Development Tools"

# Install a group
$ sudo dnf group install -y "Development Tools"

# Remove a group
$ sudo dnf group remove "Development Tools"

DNF Modules (Application Streams)

# List available module streams
$ dnf module list

# Install a specific module stream
$ sudo dnf module install nodejs:20

# Enable a stream without installing
$ sudo dnf module enable nodejs:20

DNF Modules: Application Streams

DNF modules allow multiple versions of the same application to coexist in the AppStream repository — the administrator chooses which version (stream) to install.

# List available modules and streams
$ dnf module list
Name    Stream   Profiles  Summary
nodejs  18       common    JavaScript runtime
nodejs  20 [d]   common    JavaScript runtime
php     8.1      common    PHP scripting language
php     8.2 [d]  common    PHP scripting language
# [d] = default stream for that module

# Show what packages a module stream installs
$ dnf module info nodejs:20

# Enable a specific module stream (makes packages available)
$ sudo dnf module enable nodejs:20

# Install a module (enables stream + installs default profile)
$ sudo dnf module install nodejs:20

# Switch to a different stream
$ sudo dnf module reset nodejs
$ sudo dnf module enable nodejs:18
$ sudo dnf distro-sync
Streams solve application version conflicts

Without modules, only one version of Node.js or Python could exist in a repo. Streams let the administrator choose — install nodejs:18 on one system and nodejs:20 on another, both from the same AppStream repository. The default stream is used when no stream is specified.

Package Management Quick Reference

Task Command
Search for a packagednf search KEYWORD
Show package detailsdnf info PACKAGE
Find what provides a file/commanddnf provides /path/to/file
Install a packagesudo dnf install -y PACKAGE
Update a packagesudo dnf update -y PACKAGE
Update all packagessudo dnf update -y
Remove a packagesudo dnf remove PACKAGE
Install local .rpm file (preferred)sudo dnf install -y /path/to/file.rpm
Install local .rpm (no repo needed)sudo rpm -ivh /path/to/file.rpm
List configured reposdnf repolist
Create a repo config fileCreate /etc/yum.repos.d/NAME.repo
Check if package is installedrpm -q PACKAGE
Find which package owns a filerpm -qf /path/to/file
List files in an installed packagerpm -ql PACKAGE
View transaction historydnf history
Undo a transactionsudo dnf history undo ID

Common Mistakes

Mistake What goes wrong Correct approach
Wrong or missing baseurl= in .repo file"Cannot find a valid baseurl for repo" errorCheck the URL is reachable with curl -I URL; verify repo file syntax
Spaces in the repo section IDDNF fails to parse the .repo file — repo not loadedNo spaces: [classroom-baseos] not [classroom baseos]
gpgcheck=1 without gpgkey=DNF cannot verify packages and refuses to installAdd gpgkey=URL or set gpgcheck=0 for lab repos
Using rpm -ivh when dependencies are needed"Failed dependencies" error — hard to resolve manuallyUse sudo dnf install -y /path/to/file.rpm — DNF handles deps
Forgetting -y on dnf install during examDNF prompts for confirmation — wastes exam timeAlways use dnf install -y or dnf update -y
Not verifying repo is available after creating .repo fileAssume repo works but dnf still uses the old sourceAlways run dnf repolist after creating a .repo file to confirm it is loaded

Knowledge Check

Answer these before moving to the next slide.

  1. Write the command to install the nginx package without being prompted for confirmation.
  2. Write the complete content of a .repo file that configures a repository with ID myrepo, name My Repo, base URL http://repo.example.com/rhel9, enabled, with GPG checking disabled.
  3. You have a file /tmp/myapp-1.0.x86_64.rpm. Write the preferred command to install it, and explain why it is preferred over rpm -ivh.
  4. Write the command to find which installed RPM package owns the file /etc/httpd/conf/httpd.conf.
  5. After accidentally installing a package in transaction ID 15, write the command to reverse it.
  6. What is the difference between dnf list installed and dnf repolist?

Knowledge Check — Answers

  1. sudo dnf install -y nginx
  2. Content of /etc/yum.repos.d/myrepo.repo:
    [myrepo]
    name=My Repo
    baseurl=http://repo.example.com/rhel9
    enabled=1
    gpgcheck=0
  3. sudo dnf install -y /tmp/myapp-1.0.x86_64.rpm
    Preferred because DNF automatically downloads and installs missing dependencies from configured repositories. rpm -ivh installs only the single package and fails with "Failed dependencies" if any required library is not already installed.
  4. rpm -qf /etc/httpd/conf/httpd.conf
  5. sudo dnf history undo 15 — reverses transaction 15. If it was an install, the packages are removed.
  6. dnf list installed shows all RPM packages currently installed on this system (queries the local RPM database). dnf repolist shows all configured package repositories — the sources DNF can download packages from. They answer different questions: "what is installed?" vs "where can I get packages?"

Key Takeaways

  1. DNF is the package manager — use it for all software operations. dnf install -y, dnf update -y, dnf remove, dnf search, and dnf info cover 95% of package tasks. DNF handles dependency resolution automatically from configured repositories.
  2. Repositories are configured in /etc/yum.repos.d/*.repo files. Required fields: [repoid], name=, baseurl=, enabled=1, and gpgcheck=0 (or 1 with gpgkey=). Verify with dnf repolist after creating the file.
  3. Install local .rpm files with dnf install -y /path/to/file.rpm. DNF resolves dependencies from repositories. Use rpm -ivh only when no repositories are available. Query the local RPM database with rpm -q, rpm -qf, and rpm -ql.
  4. Use dnf history undo ID to reverse a transaction. dnf history lists all past transactions. rpm -qf FILE finds which package owns a file — essential for diagnosing and fixing configuration issues.

Graded Lab

  • Run dnf repolist to see currently configured repositories. Run dnf search httpd and dnf info httpd to find and inspect the Apache package before installing it.
  • Install httpd using sudo dnf install -y httpd. Verify with rpm -q httpd. Use rpm -ql httpd | head -20 and rpm -qf /etc/httpd/conf/httpd.conf to explore installed files.
  • Create /etc/yum.repos.d/classroom.repo with entries for your classroom BaseOS and AppStream repositories. Verify with dnf repolist that the new repos appear. Install a package from the new repo to confirm it works.
  • Run dnf history to view recent transactions. Use dnf history info ID on the httpd install transaction. Then use sudo dnf history undo ID to remove it, and reinstall it again.
  • Download a sample .rpm file from the classroom server to /tmp/. Install it with sudo dnf install -y /tmp/FILENAME.rpm. Compare with what would happen using rpm -ivh (try it on a package with unmet dependencies to observe the error).
  • Run dnf check-update to see what updates are available. Use sudo dnf update -y to apply all updates. Verify with dnf history that the update transaction is recorded.
RHCSA Objective

"Install and update software packages from Red Hat CDN, a remote repository, or from the local file system." Know dnf install -y, .repo file creation with required fields, rpm -q/-qf/-ql, and dnf install -y /local/file.rpm.