LAB-PKG-02 - DNF & RedHat Package Management
DNF & RedHat Package Management
Master the dnf package manager (formerly yum) to administer software on RedHat Enterprise Linux, CentOS, AlmaLinux, and Fedora systems.
- 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.
- 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
$ # 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.
$ # 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!
$ # 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
yumvsdnfPrior to RHEL 8, the command wasyum.dnfis simply a rewritten, much faster version ofyum(Dandified Yum). If you typeyum install, it is secretly just an alias that executesdnf install. Memorizednf.- Metadata Expiration
dnfcaches 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 anddnf installsays it can’t find it, force a cache wipe usingsudo 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
tarlab).
G Guided Step by step - type exactly this and compare the result >
Exercise G1: The Basic Lifecycle
- 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) - Let’s install a classic web server, called
httpdon RedHat systems. Run:sudo dnf install httpd - Notice it automatically calculates the size and dependencies. Press
yto accept. - Now remove it using the automatic cleanup mechanism:
sudo dnf remove httpd
Exercise G2: Investigating with Info
- Let’s look up metadata without installing. Run
dnf info nginx. - 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
- Let’s view the diary of your package manager. Run:
dnf history - Look at the numbered list. You can see your
installandremoveactions from Exercise G1. - Find the ID number of the transaction where you installed
httpd. - Ask
dnfto 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!
- Use the
dnf providescommand. - Tell it to search for any package that provides an executable file named
semanage. Look in thesbinorbindirectories if needed by formatting your search like:*/semanage. - Read the output. Look for the
Name : [PACKAGE_NAME]. It will likely bepolicycoreutils-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!
- Run:
dnf grouplistto see the available predefined roles. - Read the list. If you wanted to install a “Development Tools” machine, you wouldn’t install GCC and Make individually.
- 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.
- First, search for
wgetto ensure you can download things:dnf info wget. - Assuming
wgetis 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). - You shouldn’t use
rpm -ito install it, because raw RPM cannot resolve dependencies. If your local.rpmrequires an internet dependency, it fails. dnfcan 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!