RED HAT ENTERPRISE LINUX
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
- Use DNF to search, install, update, and remove packages — Execute the core DNF commands for package lifecycle management from configured repositories
- Configure access to a remote repository — Create a
.repofile in/etc/yum.repos.d/to add a third-party or custom repository as a package source - Install packages from the local file system — Use
dnf installandrpmto install.rpmfiles directly without a network repository - Inspect packages and manage package history — Use
dnf info,rpm -q, anddnf historyto 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
.rpmfiles 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 (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
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
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
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] | Yes | Section header — unique ID, no spaces. E.g. [classroom-baseos] |
name= | Yes | Human-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=1 | URL or local path to the GPG public key file |
sslverify= | No (default 1) | 0 = skip SSL verification for HTTPS repos |
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
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
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
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 package | dnf search KEYWORD |
| Show package details | dnf info PACKAGE |
| Find what provides a file/command | dnf provides /path/to/file |
| Install a package | sudo dnf install -y PACKAGE |
| Update a package | sudo dnf update -y PACKAGE |
| Update all packages | sudo dnf update -y |
| Remove a package | sudo 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 repos | dnf repolist |
| Create a repo config file | Create /etc/yum.repos.d/NAME.repo |
| Check if package is installed | rpm -q PACKAGE |
| Find which package owns a file | rpm -qf /path/to/file |
| List files in an installed package | rpm -ql PACKAGE |
| View transaction history | dnf history |
| Undo a transaction | sudo 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" error | Check the URL is reachable with curl -I URL; verify repo file syntax |
| Spaces in the repo section ID | DNF fails to parse the .repo file — repo not loaded | No spaces: [classroom-baseos] not [classroom baseos] |
gpgcheck=1 without gpgkey= | DNF cannot verify packages and refuses to install | Add gpgkey=URL or set gpgcheck=0 for lab repos |
Using rpm -ivh when dependencies are needed | "Failed dependencies" error — hard to resolve manually | Use sudo dnf install -y /path/to/file.rpm — DNF handles deps |
Forgetting -y on dnf install during exam | DNF prompts for confirmation — wastes exam time | Always use dnf install -y or dnf update -y |
| Not verifying repo is available after creating .repo file | Assume repo works but dnf still uses the old source | Always run dnf repolist after creating a .repo file to confirm it is loaded |
Knowledge Check
Answer these before moving to the next slide.
- Write the command to install the
nginxpackage without being prompted for confirmation. - Write the complete content of a
.repofile that configures a repository with IDmyrepo, nameMy Repo, base URLhttp://repo.example.com/rhel9, enabled, with GPG checking disabled. - You have a file
/tmp/myapp-1.0.x86_64.rpm. Write the preferred command to install it, and explain why it is preferred overrpm -ivh. - Write the command to find which installed RPM package owns the file
/etc/httpd/conf/httpd.conf. - After accidentally installing a package in transaction ID 15, write the command to reverse it.
- What is the difference between
dnf list installedanddnf repolist?
Knowledge Check — Answers
sudo dnf install -y nginx-
Content of
/etc/yum.repos.d/myrepo.repo:[myrepo] name=My Repo baseurl=http://repo.example.com/rhel9 enabled=1 gpgcheck=0
sudo dnf install -y /tmp/myapp-1.0.x86_64.rpm
Preferred because DNF automatically downloads and installs missing dependencies from configured repositories.rpm -ivhinstalls only the single package and fails with "Failed dependencies" if any required library is not already installed.rpm -qf /etc/httpd/conf/httpd.confsudo dnf history undo 15— reverses transaction 15. If it was an install, the packages are removed.dnf list installedshows all RPM packages currently installed on this system (queries the local RPM database).dnf repolistshows 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
- DNF is the package manager — use it for all software operations.
dnf install -y,dnf update -y,dnf remove,dnf search, anddnf infocover 95% of package tasks. DNF handles dependency resolution automatically from configured repositories. - Repositories are configured in
/etc/yum.repos.d/*.repofiles. Required fields:[repoid],name=,baseurl=,enabled=1, andgpgcheck=0(or1withgpgkey=). Verify withdnf repolistafter creating the file. - Install local .rpm files with
dnf install -y /path/to/file.rpm. DNF resolves dependencies from repositories. Userpm -ivhonly when no repositories are available. Query the local RPM database withrpm -q,rpm -qf, andrpm -ql. - Use
dnf history undo IDto reverse a transaction.dnf historylists all past transactions.rpm -qf FILEfinds which package owns a file — essential for diagnosing and fixing configuration issues.
Graded Lab
- Run
dnf repolistto see currently configured repositories. Rundnf search httpdanddnf info httpdto find and inspect the Apache package before installing it. - Install
httpdusingsudo dnf install -y httpd. Verify withrpm -q httpd. Userpm -ql httpd | head -20andrpm -qf /etc/httpd/conf/httpd.confto explore installed files. - Create
/etc/yum.repos.d/classroom.repowith entries for your classroom BaseOS and AppStream repositories. Verify withdnf repolistthat the new repos appear. Install a package from the new repo to confirm it works. - Run
dnf historyto view recent transactions. Usednf history info IDon the httpd install transaction. Then usesudo dnf history undo IDto remove it, and reinstall it again. - Download a sample
.rpmfile from the classroom server to/tmp/. Install it withsudo dnf install -y /tmp/FILENAME.rpm. Compare with what would happen usingrpm -ivh(try it on a package with unmet dependencies to observe the error). - Run
dnf check-updateto see what updates are available. Usesudo dnf update -yto apply all updates. Verify withdnf historythat the update transaction is recorded.
"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.