Practice Use drills for recall and labs for real operating judgment.

LAB-PKG-02 - DNF & RedHat Package Management

Master the dnf package manager (formerly yum) to administer software on RedHat Enterprise Linux, CentOS, AlmaLinux, and Fedora systems.

PKG Package & Software Management

DNF & RedHat Package Management

Master the dnf package manager (formerly yum) to administer software on RedHat Enterprise Linux, CentOS, AlmaLinux, and Fedora systems.

30 min BEGINNER LINUX Curriculum-reviewed
Success criteria
  • Master the dnf package manager (formerly yum) to administer software on RedHat Enterprise Linux, CentOS, AlmaLinux, and Fedora systems.
  • Repeat the workflow without copy-paste or step-by-step prompting.
Safety notes
  • Review package names and commands before installation or removal to avoid changing the wrong system state.

Part A: The Field Guide


🎯 What & Why

There are two major families in the Linux enterprise world: The Debian Family (Ubuntu) and the RedHat Family (RHEL, CentOS, Alma, Rocky, Fedora).

While Debian uses apt and .deb files, RedHat systems use dnf and .rpm files.

If you are a professional sysadmin, you must be functionally bilingual in both package managers. Fortunately, dnf (Dandified YUM) is incredibly intuitive. It is significantly smarter than apt when it comes to resolving complex dependency webs and managing repository history.


🧠 Mental Model: The All-in-One Engine

Remember how apt requires a two-step dance? (apt update then apt upgrade).

dnf is smarter. When you run a dnf install or upgrade command, it automatically checks the remote catalog to see if its local metadata is stale before doing anything. You rarely have to manually “update” the catalog.

Underneath dnf sits rpm (RedHat Package Manager), exactly the same way dpkg sits underneath apt. dnf relies on internet repositories; rpm installs local raw files.


📖 Command Reference

Basic Operations

Searching and Installing

$ # Search for a package by name or description $ dnf search httpd

$ # Get metadata about a package before installing $ dnf info httpd

$ # Install the package and accept the GPG signing keys if necessary $ sudo dnf install httpd

$ # Remove the package. (Unlike apt, dnf automatically removes unused orphans by default!) $ sudo dnf remove httpd

System Upgrades

Because dnf automatically refreshes the catalog metadata on the fly, system updates are a streamlined one-line command.

Upgrading

$ # Upgrade all installed software to the newest available versions in the repos $ sudo dnf upgrade

$ # Upgrade just a single specific piece of software $ sudo dnf upgrade httpd

The Magic of provides

This is dnf’s most powerful superpower. Imagine you are trying to compile some code. The code throws an error: Missing file: /usr/include/libxml2/xmlversion.h. You don’t know what package contains that file. With apt, this is a nightmare to figure out. With dnf, you just ask it!

Reverse Lookups

$ # Ask dnf what package in the global repos provides this exact file path $ dnf provides /usr/include/libxml2/xmlversion.h … libxml2-devel-2.9.1-6.el7_9.6.x86_64 : Libraries, includes, etc. to develop XML


🌍 Real Scenarios

Scenario 1: The “Oh God Undo That” Button You installed a package, and it broke everything. dnf maintains a transactional history of every single action you take, like Git! You run dnf history. You see that Transaction ID 42 was the install that broke things. You run sudo dnf history undo 42. dnf surgically rolls back the install and perfectly restores the exact dependency state you had prior. apt cannot do this!

Scenario 2: The EPEL Repository RedHat Enterprise Linux is famous for being incredibly stable. The downside? Its official package repositories are tiny. It often lacks basic tools like htop. To get more software, RedHat admins enable the EPEL (Extra Packages for Enterprise Linux) repository first. sudo dnf install epel-release Now your dnf has access to thousands of more packages maintained by the Fedora project.


⚠️ Gotchas & Pitfalls

  1. yum vs dnf Prior to RHEL 8, the command was yum. dnf is simply a rewritten, much faster version of yum (Dandified Yum). If you type yum install, it is secretly just an alias that executes dnf install. Memorize dnf.
  2. Metadata Expiration dnf caches the remote repository data. By default, it won’t check for remote updates if it checked within the last 48 hours. If you know a new package dropped 5 minutes ago and dnf install says it can’t find it, force a cache wipe using sudo dnf clean all, then try again.

Part B: The Drill Deck

Terminal Required: Open a RHEL/CentOS/Fedora Linux terminal to practice. (If you are on Ubuntu, skip to tar lab).


G
Guided Step by step - type exactly this and compare the result
>

Exercise G1: The Basic Lifecycle

  1. Let’s see if your system needs patching: sudo dnf check-update (It might take a moment as it checks the remote servers built-in)
  2. Let’s install a classic web server, called httpd on RedHat systems. Run: sudo dnf install httpd
  3. Notice it automatically calculates the size and dependencies. Press y to accept.
  4. Now remove it using the automatic cleanup mechanism: sudo dnf remove httpd

Exercise G2: Investigating with Info

  1. Let’s look up metadata without installing. Run dnf info nginx.
  2. Review the output. You can clearly see the Version, the exact Repository it belongs to, its License, and the Architectures it supports.

Exercise G3: The Time Machine

  1. Let’s view the diary of your package manager. Run: dnf history
  2. Look at the numbered list. You can see your install and remove actions from Exercise G1.
  3. Find the ID number of the transaction where you installed httpd.
  4. Ask dnf to tell you exactly what happened during that ID event: dnf history info [ID]
S
Solo Task described, hints available - figure it out
>

Exercise S1: Finding the Missing Piece

You are trying to run a script, but it throws an error saying it cannot find the command semanage. You try to dnf install semanage but it says “No match for argument”. The tool is named something else!

  1. Use the dnf provides command.
  2. Tell it to search for any package that provides an executable file named semanage. Look in the sbin or bin directories if needed by formatting your search like: */semanage.
  3. Read the output. Look for the Name : [PACKAGE_NAME]. It will likely be policycoreutils-python-utils.

Exercise S2: Group Installs

Sometimes you need to set up a server for a specific role (like a Web Server or Development Machine), which requires 50 different packages. dnf groups them for you!

  1. Run: dnf grouplist to see the available predefined roles.
  2. Read the list. If you wanted to install a “Development Tools” machine, you wouldn’t install GCC and Make individually.
  3. You would just run sudo dnf groupinstall "Development Tools". (Don’t actually run this unless you want 200MB of compilers!)
M
Mission Real scenario - no hints, combine multiple skills
>

Mission M1: The Raw RPM

Normally dnf reaches out to the internet to grab packages. But sometimes, a vendor (like a proprietary VPN company) just gives you an .rpm file to download to your server manually.

  1. First, search for wget to ensure you can download things: dnf info wget.
  2. Assuming wget is installed, use it to download a tiny, safe RPM file directly from a server. (If you don’t have a link handy, we’ll pretend we downloaded /tmp/example.rpm).
  3. You shouldn’t use rpm -i to install it, because raw RPM cannot resolve dependencies. If your local .rpm requires an internet dependency, it fails.
  4. dnf can install local files and reach out to the internet to satisfy their dependencies simultaneously!

Your Mission: Formulate the command to use dnf to install a local file sitting at /tmp/example.rpm.

Hint: The syntax is exactly the same as installing from the internet, you just provide an absolute or relative filepath instead of a package name!