RED HAT ENTERPRISE LINUX
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
- Explain the RPM package format — Describe what an RPM package contains and how package naming works
-
Install and update packages with dnf —
Use
dnf install,dnf update, and related subcommands to manage software from repositories -
Remove packages with dnf —
Use
dnf removeto uninstall packages and their unused dependencies -
Query packages with rpm and dnf —
Use
rpm -qanddnfqueries 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)
x86_64 — 64-bit Intel or AMD processors (most servers)
aarch64 — 64-bit ARM processors
noarch — architecture-independent (scripts, documentation)
dnf: The Package Manager
dnf — Dandified 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 package | sudo dnf install packagename |
| Remove a package | sudo dnf remove packagename |
| Update one package | sudo dnf update packagename |
| Update all packages | sudo dnf update |
| Search for a package by name or description | dnf search keyword |
| Show package details | dnf info packagename |
| List installed packages | dnf list installed |
| List available packages | dnf list available |
| Find which package provides a file | dnf provides /path/to/file |
| View transaction history | dnf 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
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
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
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
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.
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 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
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
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 httpd | Package name-version-release or "not installed" |
| All installed packages | rpm -qa | Every package in the RPM database |
| Package information | rpm -qi httpd | Description, version, vendor, install date, size |
| Files installed by package | rpm -ql httpd | Full paths of every file the package installed |
| Config files only | rpm -qc httpd | Only the configuration files from the package |
| Documentation files only | rpm -qd httpd | Only the documentation files from the package |
| Which package owns a file | rpm -qf /usr/sbin/httpd | The package name that installed the given file |
| Package dependencies | rpm -qR httpd | Libraries and capabilities the package requires |
| Scripts in the package | rpm -q --scripts httpd | Pre/post install and uninstall scripts |
| Package changelog | rpm -q --changelog httpd | List 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
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
| Code | Meaning |
|---|---|
S | File size differs |
5 | MD5 checksum differs |
M | File permissions differ |
U | File owner (user) differs |
G | File group differs |
T | Modification 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.
- Write the command to install the
httpdpackage without being prompted for confirmation. - A task requires the
sealertcommand, which is not installed. Write the dnf command to find which package provides it. - Write the rpm command to find out which package installed the file
/etc/ssh/sshd_config. - Write the rpm command to list every file installed by the
openssh-serverpackage. - You ran
sudo dnf install vim-enhancedand now want to reverse it. What is the fastest way to undo the installation? - What does
rpm -V openssh-serverdo, and what does no output mean?
Knowledge Check — Answers
sudo dnf install -y httpd— the-yflag answers yes to all prompts automatically.dnf provides '*/sealert'— the wildcard*/searches all paths across all packages in the enabled repositories. Quotes prevent shell glob expansion.rpm -qf /etc/ssh/sshd_config— the-fflag queries by file path and returns the package name that owns it.rpm -ql openssh-server— the-lflag lists all files the package installed, with full paths.sudo dnf history undofollowed by the transaction ID shown indnf history. The most recent transaction can also be undone withsudo dnf history undo last.rpm -V openssh-servercompares 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
-
Use dnf for all install, remove, and update actions.
dnf install,dnf remove, anddnf updatehandle dependency resolution automatically. Never userpm -iorrpm -efor package management — use those only for querying. -
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. -
The four essential rpm -q queries.
rpm -q pkg(installed?),rpm -ql pkg(what files?),rpm -qf /path(what package owns this file?), andrpm -qi pkg(package details). These are tested directly on the RHCSA exam. -
dnf history undoreverses a transaction safely. If an installation causes a problem, usednf history undowith the transaction ID rather than manually removing packages. It reverses the exact transaction including all automatically installed dependencies.
Graded Lab
- Use
dnf searchto find a package that provides an HTTP server. Usednf infoto view its description and installed size before installing. - Install
httpdusingdnf install -y. Confirm the installation withrpm -q httpd. - Use
rpm -ql httpdto list the files the package installed. Identify the main configuration file and the server binary. - Use
rpm -qf /etc/servicesto find which package owns that file. Then userpm -qdon that package to list its documentation files. - Use
dnf provides '*/semanage'to find the package that provides thesemanagecommand, then install it. - Remove
httpdwithdnf remove. Usednf historyto confirm the removal was recorded, then usednf history undoto reinstall it.
"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.