Advanced package management (RPM, YUM, DNF)

Advanced Package Management in RHEL: RPM, YUM, and DNF
Red Hat Enterprise Linux (RHEL) uses a robust package management system to install, update, and manage software. Below is a detailed breakdown of the core tools—RPM, YUM, and DNF—and their advanced use cases for experienced administrators:


1. RPM (Red Hat Package Manager)

Basics:

  • Low-level tool for installing, querying, and managing individual .rpm packages.
  • Does not resolve dependencies automatically (unlike YUM/DNF).

Advanced Use Cases:

  • Querying Packages:
  rpm -qa                        # List all installed packages
  rpm -qi <package>              # Show package info
  rpm -ql <package>              # List files installed by a package
  rpm -qf /path/to/file          # Find which package owns a file
  • Verify Package Integrity:
  rpm -V <package>               # Check for changes to package files
  rpm --checksig <package.rpm>   # Verify GPG signature
  • Install/Remove Packages Manually:
  rpm -ivh <package.rpm>         # Install with verbose output
  rpm -e <package>               # Remove a package (if no dependencies)
  • Extract Files from RPM Without Installing:
  rpm2cpio <package.rpm> | cpio -idmv

Key Notes:

  • Use RPM for direct control over specific packages (e.g., air-gapped systems).
  • Dependency resolution must be handled manually.

2. YUM (Yellowdog Updater Modified)

Basics:

  • High-level tool that automates dependency resolution using RPM under the hood.
  • Default in RHEL 7, deprecated in RHEL 8/9 in favor of DNF (but still aliased as yum).

Advanced Use Cases:

  • Manage Repositories:
  yum repolist                   # List enabled repositories
  yum-config-manager --add-repo=http://repo.url
  yum-config-manager --disable <repo-id>
  • Clean Up:
  yum clean all                  # Remove cached metadata and packages
  yum autoremove                 # Remove unused dependencies
  • Downgrade Packages:
  yum history list               # View transaction history
  yum history undo <transaction-id>  # Roll back a specific update
  • Version Locking:
  yum install yum-plugin-versionlock
  yum versionlock <package>      # Prevent updates to a package
  • Security Updates:
  yum updateinfo list security   # List available security patches
  yum update --security          # Apply only security updates

Key Notes:

  • Slower than DNF due to Python 2 dependency (in older versions).
  • Still useful for legacy scripts, but DNF is preferred in RHEL 8/9.

3. DNF (Dandified YUM)

Basics:

  • Modern replacement for YUM in RHEL 8/9.
  • Written in Python 3 with faster dependency resolution and improved performance.

Advanced Use Cases:

  • Modularity (RHEL 8/9 AppStream):
  dnf module list                 # List available modules
  dnf module install nodejs:14    # Install a specific module stream
  dnf module reset nodejs         # Reset to default module
  • Advanced Queries:
  dnf repoquery <pattern>         # Search packages in repositories (even if not installed)
  dnf provides /path/to/file      # Find which package provides a file
  • Transaction History:
  dnf history                     # View all transactions
  dnf history undo <ID>           # Roll back a transaction
  dnf history rollback            # Revert to a previous state
  • Groups and Environments:
  dnf group list                  # List package groups (e.g., "Development Tools")
  dnf group install "Development Tools"
  • Parallel Downloads & Delta RPMs:
  # Enable delta RPMs in /etc/dnf/dnf.conf:
  deltarpm=1
  • Automate with Scripts:
  dnf install -y --nogpgcheck <package>   # Skip GPG checks (use cautiously)
  dnf update --downloadonly               # Download updates without installing

Key Differences from YUM:

  • Faster dependency resolution with libsolv library.
  • Better support for modular packages and parallel operations.
  • Cleaner command syntax and improved plugins.

Best Practices for Advanced Admins

  1. Use DNF as Default:
  • In RHEL 8/9, yum is an alias for dnf, but use dnf for scripting to avoid future compatibility issues.
  1. Secure Repositories:
  • Always enable GPG checks for repositories.
  • Use rpm --import <key> to add trusted GPG keys.
  1. Automate with Ansible:
  • Use the dnf Ansible module for idempotent package management: “`yaml
    • name: Install Apache
      dnf:
      name: httpd
      state: latest
      “`
  1. Resolve Dependency Hell:
  • Use dnf repoquery --deplist <package> to analyze dependencies.
  • Remove conflicting packages with dnf remove --duplicates.
  1. Create Local Repositories:
  • Use createrepo to build a local mirror for air-gapped systems.

Comparison Table

FeatureRPMYUMDNF
Dependency Resolution❌ No✔️ Yes✔️ Yes (faster)
Modularity Support❌ No❌ Limited✔️ Full
Transaction History❌ No✔️ Basic✔️ Advanced
PerformanceFast (per-pkg)SlowVery Fast
RHEL VersionAllRHEL 7 (legacy)RHEL 8/9

Troubleshooting Tips

  • Broken Dependencies:
  dnf clean all && dnf autoremove
  dnf distro-sync                # Resync packages with repository
  • Corrupted RPM Database:
  rm -f /var/lib/rpm/__db.*       # Remove corrupted DB files
  rpm --rebuilddb                # Rebuild RPM database
  • Debug Package Issues:
  dnf --verbose install <package>  # Show detailed installation logs

By mastering these tools, you’ll streamline deployments, ensure system consistency, and troubleshoot complex package issues efficiently.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *