Installing and Removing
RPM Packages

Install and remove RPM software packages

CIS126RH | RHEL System Administration 1
Mesa Community College

Managing software is one of the most frequent tasks a RHEL administrator performs. Installing services, updating the system, removing unused packages, and querying what is installed are all daily operations. This module covers both dnf — the high-level package manager used for most tasks — and rpm — the low-level tool for querying and working with individual package files. Both are tested on the RHCSA exam.

Learning Objectives

  1. Explain the RPM package format — Describe what an RPM package contains and how package naming works
  2. Install and update packages with dnf — Use dnf install, dnf update, and related subcommands to manage software from repositories
  3. Remove packages with dnf — Use dnf remove to uninstall packages and their unused dependencies
  4. Query packages with rpm and dnf — Use rpm -q and dnf queries to find, inspect, and verify installed and available packages

The RPM Package Format

An RPM package is a compressed archive containing software files and the metadata needed to install, verify, and remove them.

  • The files to be installed — binaries, libraries, configuration, documentation
  • Pre- and post-install scripts that run during installation or removal
  • Dependency information — what other packages must be installed first
  • A GPG signature that verifies the package came from a trusted source

RPM Package Naming Convention

Every RPM filename follows this structure:

httpd-2.4.57-11.el9.x86_64.rpm
# name  - version - release . dist . arch . rpm

# Name:    httpd
# Version: 2.4.57   (upstream software version)
# Release: 11       (Red Hat build number)
# Dist:    el9      (Enterprise Linux 9)
# Arch:    x86_64   (64-bit Intel/AMD)
Architecture values

x86_64 — 64-bit Intel or AMD processors (most servers)
aarch64 — 64-bit ARM processors
noarch — architecture-independent (scripts, documentation)

dnf: The Package Manager

dnfDandified YUM — is the primary package management tool on RHEL 9. It handles repository access, dependency resolution, and calls RPM to perform the actual installation.

Task Command
Install a packagesudo dnf install packagename
Remove a packagesudo dnf remove packagename
Update one packagesudo dnf update packagename
Update all packagessudo dnf update
Search for a package by name or descriptiondnf search keyword
Show package detailsdnf info packagename
List installed packagesdnf list installed
List available packagesdnf list available
Find which package provides a filednf provides /path/to/file
View transaction historydnf history

Installing Packages with dnf install

# Install a single package — dnf resolves all dependencies
$ sudo dnf install httpd
Dependencies resolved.
Installing:  httpd  2.4.57-11.el9  x86_64  2.5 MB
Installing dependencies: apr, apr-util, ...
Is this ok [y/N]: y
Complete!

# Install multiple packages in one command
$ sudo dnf install httpd mariadb-server php

# Install without confirmation prompt
$ sudo dnf install -y httpd

# Install a specific version
$ sudo dnf install httpd-2.4.57-11.el9

# Install a local .rpm file — dnf resolves deps from repos
$ sudo dnf install /tmp/mypkg-1.0.x86_64.rpm

# Dry run — show what would be installed without doing it
$ sudo dnf install --setopt=tsflags=test httpd
$ dnf install -y --assumeno httpd
Use -y in scripts; omit it interactively

The -y flag answers yes to all prompts automatically — essential in scripts and Ansible, but removes your chance to review what will be installed when working interactively.

Searching and Finding Packages

Before installing, find the correct package name.

# Search package names and descriptions for a keyword
$ dnf search web server
httpd.x86_64 : Apache HTTP Server
nginx.x86_64 : A high performance web server

# Show full details about a package — size, description, URL
$ dnf info httpd
Name        : httpd
Version     : 2.4.57
Summary     : Apache HTTP Server
Description : The Apache HTTP Server is ...

# Find which package provides a command or file
$ dnf provides /usr/bin/dig
bind-utils-32:9.16.23 : Utilities for querying DNS

$ dnf provides '*/bin/nmap'
nmap-3:7.92-3.el9 : Network exploration tool

# List all available packages from a specific repo
$ dnf list available --disablerepo='*' --enablerepo=rhel-9-appstream
RHCSA Focus

dnf provides is essential for the exam. When a task requires a command you cannot find, use dnf provides '*/command-name' to identify the package that installs it.

Updating Packages

# Check what updates are available — does not install
$ dnf check-update
kernel.x86_64          5.14.0-362.8.1.el9    rhel-9-baseos
httpd.x86_64           2.4.57-11.el9         rhel-9-appstream

# Update a single package
$ sudo dnf update httpd

# Update all packages on the system
$ sudo dnf update

# Update security-related packages only
$ sudo dnf update --security

# Upgrade is an alias for update — they are identical on RHEL 9
$ sudo dnf upgrade

# Downgrade a package to a previous version
$ sudo dnf downgrade httpd
Kernel updates are additive

When a new kernel is installed, the old kernel is kept. The system boots the newest kernel by default but the previous one remains available as a fallback. Use sudo dnf remove --oldinstallonly to clean up old kernels.

Removing Packages with dnf remove

# Remove a package and its unused dependencies
$ sudo dnf remove httpd
Removing:  httpd x86_64 2.4.57-11.el9
Removing unused dependencies: httpd-filesystem, ...
Is this ok [y/N]: y

# Remove multiple packages at once
$ sudo dnf remove httpd mariadb-server

# Remove a package but keep its dependencies
$ sudo dnf remove --noautoremove httpd

# Remove packages that were installed as dependencies
# but are no longer needed by anything
$ sudo dnf autoremove
Configuration files are kept on removal

By default, dnf remove keeps configuration files in /etc. This lets you reinstall the package and pick up where you left off. If you want a truly clean removal, delete the config files manually after removing the package.

Review before confirming

Always read the removal summary before answering yes. dnf may propose removing packages you still need if they appear to be unused dependencies.

Package Groups

A package group is a named collection of related packages that can be installed or removed as a unit — useful for setting up a role or environment without knowing every individual package name.

# List available package groups
$ dnf group list
Available Environment Groups:
   Server
   Minimal Install
   Workstation
Available Groups:
   RPM Development Tools
   System Tools

# Show what a group contains
$ dnf group info "System Tools"

# Install a group
$ sudo dnf group install "System Tools"

# Remove a group
$ sudo dnf group remove "System Tools"
Group names with spaces require quotes

Group names that contain spaces must be enclosed in single or double quotes. Alternatively, use the group ID shown in parentheses, which has no spaces: dnf group install system-tools

dnf History and Undo

DNF records every transaction. You can review the history and reverse previous operations — a powerful safety net.

# Show recent transactions
$ dnf history
ID  Command              Date              Action  Altered
12  install httpd        2026-05-25 09:05  Install  5
11  remove nginx         2026-05-24 14:00  Removed  3
10  update               2026-05-23 10:00  Update  42

# Show what a specific transaction did
$ dnf history info 12

# Undo a specific transaction — reverses it exactly
$ sudo dnf history undo 12

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

# Roll back the system to the state after a specific transaction
$ sudo dnf history rollback 10
Undo before troubleshooting alternatives

If a recent package installation broke something, dnf history undo is faster than manually removing packages. It reverses the entire transaction, including dependencies that were automatically installed.

rpm: Querying Installed Packages

rpm -q queries the RPM database of installed packages. No repositories or network access are needed — it reads only what is already on the system.

# Is a package installed? Shows name-version-release if yes
$ rpm -q httpd
httpd-2.4.57-11.el9.x86_64

# List all installed packages
$ rpm -qa

# List all files installed by a package
$ rpm -ql httpd
/etc/httpd/conf/httpd.conf
/usr/sbin/httpd
/usr/share/man/man8/httpd.8.gz

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

# Show package information (description, version, install date)
$ rpm -qi httpd
RHCSA High-Value Query

rpm -qf /path/to/file — "which package installed this file?" — is one of the most commonly tested rpm queries on the exam.

rpm Query Options Reference

Query Command What it shows
Is it installed?rpm -q httpdPackage name-version-release or "not installed"
All installed packagesrpm -qaEvery package in the RPM database
Package informationrpm -qi httpdDescription, version, vendor, install date, size
Files installed by packagerpm -ql httpdFull paths of every file the package installed
Config files onlyrpm -qc httpdOnly the configuration files from the package
Documentation files onlyrpm -qd httpdOnly the documentation files from the package
Which package owns a filerpm -qf /usr/sbin/httpdThe package name that installed the given file
Package dependenciesrpm -qR httpdLibraries and capabilities the package requires
Scripts in the packagerpm -q --scripts httpdPre/post install and uninstall scripts
Package changelogrpm -q --changelog httpdList of changes across package versions

Querying Package Files with rpm -p

The -p flag lets you query an RPM file directly — before installing it. Combine it with any -q option to inspect a package file.

# Query an .rpm file before installing it
$ rpm -qip /tmp/mypkg-1.0.x86_64.rpm
Name        : mypkg
Version     : 1.0
Description : ...

# List files that would be installed by an .rpm file
$ rpm -qlp /tmp/mypkg-1.0.x86_64.rpm

# Check what the package requires before installing
$ rpm -qRp /tmp/mypkg-1.0.x86_64.rpm

# Verify a package's GPG signature
$ rpm -K /tmp/mypkg-1.0.x86_64.rpm
/tmp/mypkg-1.0.x86_64.rpm: digests signatures OK
Inspect before installing

When installing a package from an untrusted source, use rpm -qip to review its contents and rpm -K to verify its signature before committing to the installation.

Verifying Installed Packages

rpm -V compares the installed files against the package's stored checksums to detect modifications, missing files, or permission changes.

# Verify a specific package
$ rpm -V httpd
S.5....T.  c /etc/httpd/conf/httpd.conf
# S = file size changed
# 5 = MD5 checksum differs
# T = modification time changed
# c = config file

# No output means all files match the original package
$ rpm -V openssh-server
(no output — all files are intact)

# Verify every installed package — slow but thorough
$ rpm -Va
CodeMeaning
SFile size differs
5MD5 checksum differs
MFile permissions differ
UFile owner (user) differs
GFile group differs
TModification time differs

rpm vs dnf: When to Use Each

Task Use Why
Install a package from a repository dnf install Resolves and installs all dependencies automatically
Remove a package dnf remove Handles dependency cleanup; safer than rpm -e
Update packages dnf update Finds updates in repositories; handles dependencies
Search for a package by keyword dnf search Searches repository metadata — not limited to installed packages
Is a package installed? rpm -q Fast local check — no network needed
What files did a package install? rpm -ql Queries the RPM database directly
Which package owns a file? rpm -qf Only rpm can answer this from the local database
Verify package integrity rpm -V Checks checksums against original package metadata

Common Mistakes

Mistake What goes wrong Correct approach
Using rpm -i to install from a repository No dependency resolution — installation fails or leaves the system broken Use dnf install to let dnf resolve all dependencies
Removing a package with rpm -e Dependencies of the removed package may break other software Use dnf remove to handle dependency cleanup safely
Not reading the removal summary before confirming Accidentally removes packages that are still needed Always review the list of packages to be removed before answering yes
Searching with rpm -qa | grep for uninstalled packages Only finds installed packages — misses available ones in repositories Use dnf search or dnf provides for repository searches
Confusing dnf update and dnf upgrade On RHEL 9 they are identical — no practical difference Either works; dnf update is the conventional choice on RHEL
Installing without verifying repositories are configured dnf reports "No package available" even for standard packages Run dnf repolist first to confirm repositories are active

Knowledge Check

Answer these before moving to the next slide.

  1. Write the command to install the httpd package without being prompted for confirmation.
  2. A task requires the sealert command, which is not installed. Write the dnf command to find which package provides it.
  3. Write the rpm command to find out which package installed the file /etc/ssh/sshd_config.
  4. Write the rpm command to list every file installed by the openssh-server package.
  5. You ran sudo dnf install vim-enhanced and now want to reverse it. What is the fastest way to undo the installation?
  6. What does rpm -V openssh-server do, and what does no output mean?

Knowledge Check — Answers

  1. sudo dnf install -y httpd — the -y flag answers yes to all prompts automatically.
  2. dnf provides '*/sealert' — the wildcard */ searches all paths across all packages in the enabled repositories. Quotes prevent shell glob expansion.
  3. rpm -qf /etc/ssh/sshd_config — the -f flag queries by file path and returns the package name that owns it.
  4. rpm -ql openssh-server — the -l flag lists all files the package installed, with full paths.
  5. sudo dnf history undo followed by the transaction ID shown in dnf history. The most recent transaction can also be undone with sudo dnf history undo last.
  6. rpm -V openssh-server compares every file installed by the package against the checksums stored in the RPM database when the package was installed. No output means all files are intact and unmodified — the package is in its original installed state.

Key Takeaways

  1. Use dnf for all install, remove, and update actions. dnf install, dnf remove, and dnf update handle dependency resolution automatically. Never use rpm -i or rpm -e for package management — use those only for querying.
  2. dnf provides '*/command' finds the package you need. When a required command is not installed, this query searches all repository packages to identify which one provides it. The wildcard and quotes are both required.
  3. The four essential rpm -q queries. rpm -q pkg (installed?), rpm -ql pkg (what files?), rpm -qf /path (what package owns this file?), and rpm -qi pkg (package details). These are tested directly on the RHCSA exam.
  4. dnf history undo reverses a transaction safely. If an installation causes a problem, use dnf history undo with the transaction ID rather than manually removing packages. It reverses the exact transaction including all automatically installed dependencies.

Graded Lab

  • Use dnf search to find a package that provides an HTTP server. Use dnf info to view its description and installed size before installing.
  • Install httpd using dnf install -y. Confirm the installation with rpm -q httpd.
  • Use rpm -ql httpd to list the files the package installed. Identify the main configuration file and the server binary.
  • Use rpm -qf /etc/services to find which package owns that file. Then use rpm -qd on that package to list its documentation files.
  • Use dnf provides '*/semanage' to find the package that provides the semanage command, then install it.
  • Remove httpd with dnf remove. Use dnf history to confirm the removal was recorded, then use dnf history undo to reinstall it.
RHCSA Objective

"Install and remove RPM software packages." Fluency with dnf install, dnf remove, dnf provides, and the rpm -q query family is required throughout the entire exam.