Skip to main content

Chapter 10.2 - yum/dnf (Red Hat/CentOS)

Learning Objectives​

By the end of this chapter, you will be able to:

  • Use yum and dnf to install packages
  • Update the system
  • Manage repositories
  • Understand package groups
  • Use transactions

yum vs dnf​

yum (Classic)​

Yellowdog Updater Modified:

  • Red Hat/CentOS 7 and earlier
  • Still available
  • Classic interface

dnf (Modern)​

Dandified YUM:

  • Red Hat/CentOS 8+ and Fedora
  • Successor to yum
  • Faster and modern
  • Same syntax as yum

Note: yum is often an alias for dnf on recent systems.


Basic Commands​

Update​

# Update package list
sudo yum check-update
sudo dnf check-update

# Update packages
sudo yum update
sudo dnf upgrade

# Update specific package
sudo yum update package-name
sudo dnf upgrade package-name

Installation​

# Install package
sudo yum install package-name
sudo dnf install package-name

# Install multiple packages
sudo yum install package1 package2 package3

# Install without confirmation
sudo yum install -y package-name

# Install from .rpm file
sudo yum localinstall file.rpm

Removal​

# Remove package
sudo yum remove package-name
sudo dnf remove package-name

# Remove package and dependencies
sudo yum autoremove package-name

# Clean cache
sudo yum clean all
sudo dnf clean all

Search and Information​

# Search package
yum search keyword
dnf search keyword

# Search by name
yum list package-name
dnf list package-name

# Package information
yum info package-name
dnf info package-name

# List installed packages
yum list installed
dnf list installed

# List available packages
yum list available
dnf list available

Information​

# Detailed information
yum info package-name

# Dependencies
yum deplist package-name
dnf repoquery --deplist package-name

# Package content
rpm -ql package-name

Repositories​

View Repositories​

# List enabled repositories
yum repolist
dnf repolist

# All repositories
yum repolist all
dnf repolist all

# Repository information
yum repoinfo repo-name
dnf repoinfo repo-name

Add Repository​

# Install RPM repository
sudo yum install epel-release
sudo dnf install epel-release

# Add repository manually
# Create file: /etc/yum.repos.d/my-repo.repo

[my-repo]
name=My Repository
baseurl=http://repo.example.com/rhel/$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://repo.example.com/RPM-GPG-KEY

# Reload
sudo yum makecache
sudo dnf makecache

EPEL (Extra Packages)​

# Install EPEL
sudo yum install epel-release
sudo dnf install epel-release

# Verify
yum repolist | grep epel

Package Groups​

Group Management​

# List available groups
yum grouplist
dnf group list

# Group information
yum groupinfo "Development Tools"
dnf group info "Development Tools"

# Install group
sudo yum groupinstall "Development Tools"
sudo dnf group install "Development Tools"

# Remove group
sudo yum groupremove "Development Tools"

Transactions and History​

History​

# View history
yum history
dnf history

# View specific transaction
yum history info 5
dnf history info 5

# Undo transaction
sudo yum history undo 5
sudo dnf history undo 5

# Redo transaction
sudo yum history redo 5

Practical Examples​

Complete Installation​

# Update
sudo yum check-update

# Install package
sudo yum install httpd

# Start service
sudo systemctl start httpd
sudo systemctl enable httpd

# Verify
systemctl status httpd

System Update​

#!/bin/bash
# Update script

echo "Checking for updates..."
sudo yum check-update

echo "Updating packages..."
sudo yum update -y

echo "Cleaning up..."
sudo yum clean all

echo "Done!"

Troubleshooting​

Dependencies​

# Resolve dependencies
sudo yum deplist package-name

# Force installation
sudo rpm -ivh --nodeps package.rpm # Caution!

Cache​

# Clean cache
sudo yum clean all
sudo yum clean metadata
sudo yum clean packages

# Rebuild cache
sudo yum makecache

Summary​

In this chapter, you learned:

yum/dnf: Red Hat/CentOS/Fedora package managers
Commands: install, update, remove, search, info
Repositories: repolist, epel-release, .repo files
Groups: grouplist, groupinstall
History: history, undo, redo
Practice: Installation, update, maintenance


Next Steps​

Chapter 10.3: Compiling from Source
Module 11: Monitoring and Logs


Chapter created on: December 2024