The Enterprise Choice: dnf, yum, and rpm
·TechSoftware Development

The Enterprise Choice: dnf, yum, and rpm

Master software management for Red Hat, CentOS, and Fedora. Learn the power of 'dnf' (Dandified YUM) and the low-level 'rpm' tool. Understand how groups and repositories work in the enterprise Linux world.

dnf, yum, and rpm: Software for the Data Center

While Ubuntu is popular for developers and desktops, the "Enterprise" world of banking, government, and massive data centers is dominated by the Red Hat family. This includes RHEL (Red Hat Enterprise Linux), Fedora, and clones like AlmaLinux and Rocky Linux.

The Red Hat family uses a different set of tools:

  1. dnf / yum: The high-level managers (Equivalent to apt).
  2. rpm: The low-level installer (Equivalent to dpkg).

In this lesson, we will learn how to navigate the Red Hat ecosystem.


1. The High-Level Manager: dnf (formerly yum)

For 20 years, the standard was yum. Today, it has been replaced by dnf (Dandified YUM), which is faster and handles dependencies better. On most systems, typing yum actually just runs dnf in the background.

The Essential dnf Workflow:

# Check for updates and install them all
sudo dnf check-update
sudo dnf upgrade

# Search for a package
dnf search postgresql

# Install and Remove
sudo dnf install postgresql-server
sudo dnf remove postgresql-server

2. The Power of "Groups"

Red Hat systems have a great feature called Package Groups. Instead of installing 50 separate tools for "Development," you can install a single group.

# See all available groups
dnf group list

# Install everything needed for C/C++ development
sudo dnf groupinstall "Development Tools"

3. rpm: The Red Hat Package Manager

If you have a local .rpm file, you use the rpm command.

Key Commands:

  • sudo rpm -ivh package.rpm: install, verbose, hash (shows progress).
  • rpm -qa: Query All—lists every package on the system.
  • rpm -qi package_name: Show detailed Info.
  • rpm -ql package_name: Show Locations (where the files are).

4. History and Undo: The dnf Secret Weapon

Have you ever installed a package, only to realize it broke your system, and now you don't remember which 5 dependencies it installed? dnf has a time machine.

# See every transaction that ever happened
dnf history

# See the details of a specific transaction
dnf history info 42

# UNDO everything that happened in transaction 42
sudo dnf history undo 42

5. Repositories: /etc/yum.repos.d/

Just like Ubuntu has sources.list, Red Hat has a directory where each repository gets its own .repo file.

# List all active repositories
dnf repolist

6. Example: Repository Health Monitor (Python)

If a repository is slow or offline, your dnf commands will hang. Here is a Python script that checks the accessibility of the configured Red Hat repositories.

import os
import re
import subprocess

def audit_yum_repos():
    """
    Parses .repo files and checks if they are enabled.
    """
    repo_dir = "/etc/yum.repos.d/"
    if not os.path.exists(repo_dir):
        return "Not a Red Hat/Fedora system."

    enabled_repos = []
    
    for filename in os.listdir(repo_dir):
        if filename.endswith(".repo"):
            path = os.path.join(repo_dir, filename)
            with open(path, 'r') as f:
                content = f.read()
                # Find the [name] and 'enabled=1'
                matches = re.findall(r"\[(.*?)\]", content)
                if "enabled=1" in content:
                    enabled_repos.extend(matches)
                    
    return enabled_repos

if __name__ == "__main__":
    repos = audit_yum_repos()
    print("--- Active Red Hat Repositories ---")
    if isinstance(repos, list):
        for r in repos:
            print(f"  [ENABLED] {r}")
    else:
        print(repos)

7. Professional Tip: Use 'EPEL'

The standard Red Hat repositories are very small to ensure maximum stability. Most professionals immediately add the EPEL (Extra Packages for Enterprise Linux) repository to get access to common tools like htop, nginx, and git.

sudo dnf install epel-release

8. Summary

The Red Hat family is designed for consistency and scale.

  • dnf is the modern, high-level tool.
  • rpm handles local files and deep queries.
  • dnf history is an essential tool for "Safe" administration.
  • Use groupinstall to set up workflows in seconds.
  • EPEL is the mandatory extension for missing software.

In the next lesson, we will move away from pre-built packages and learn to Build Software from Source using make and install.

Quiz Questions

  1. How does dnf history undo help a sysadmin who made a mistake?
  2. What is the equivalent of apt search in the Red Hat world?
  3. What is the "EPEL" repository and why is it so common?

Continue to Lesson 4: Managing Software from Source—make and install.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn