Yum (Yellowdog Updater Modified) and DNF (Dandified Yum) are powerful package managers for Red Hat-based Linux distributions including RHEL, CentOS, Fedora, AlmaLinux, and Rocky Linux. This comprehensive guide covers essential commands for installing, updating, removing, and managing software packages, repositories, and dependencies. Whether you’re a system administrator managing enterprise servers or learning Linux package management, mastering yum and dnf commands is crucial for maintaining secure, up-to-date systems.
📑 Table of Contents
- Understanding Yum vs DNF
- What’s the Difference?
- Basic Package Management
- Installing Packages
- Removing Packages
- Updating Packages
- Searching and Querying Packages
- Search for Packages
- Get Package Information
- List Packages
- Package Groups
- Working with Group Packages
- Common Package Groups
- Repository Management
- List Repositories
- Enable/Disable Repositories
- Add New Repositories
- Cache Management
- Transaction History
- View History
- Undo/Redo Transactions
- Security Updates
- List Security Updates
- Apply Security Updates
- Download Packages Without Installing
- Download Only
- Download Updates
- Dependency Management
- Check Dependencies
- Resolve Dependency Issues
- Advanced Commands
- Downgrade Packages
- Lock Package Versions (Prevent Updates)
- Show Changelog
- Debugging and Troubleshooting
- Verbose Output
- Check System
- Performance Optimization
- Speed Up Operations
- Common Use Cases
- System Maintenance
- Find and Install Files
- Frequently Asked Questions
- What’s the difference between yum update and yum upgrade?
- How do I prevent a specific package from being updated?
- Can I use yum commands on RHEL 8/9 systems?
- How do I install packages from EPEL repository?
- What does “yum clean all” do and when should I use it?
- How do I list all files installed by a package?
- Can I download packages for offline installation?
- How do I rollback a package to previous version?
- What’s the difference between yum remove and yum autoremove?
- How do I check which repository a package comes from?
- Conclusion
Understanding Yum vs DNF
What’s the Difference?
Yum (used in RHEL/CentOS 7 and earlier):
- Python 2 based
- Slower dependency resolution
- Legacy but still widely used
DNF (default in RHEL/CentOS 8+, Fedora):
- Python 3 based
- Faster dependency resolution
- Better performance and memory usage
- Backward compatible with yum commands
Good news: Most commands work identically – just replace “yum” with “dnf”!
Basic Package Management
Installing Packages
# Install single package
yum install httpd
dnf install httpd
# Install multiple packages
yum install httpd mariadb-server php
dnf install nginx postgresql redis
# Install without confirmation prompt
yum install -y package-name
dnf install -y package-name
# Install specific version
yum install httpd-2.4.6-97
dnf install httpd-2.4.51-7
# Install from local RPM file
yum install /path/to/package.rpm
dnf install /path/to/package.rpm
# Reinstall package (if corrupted)
yum reinstall httpd
dnf reinstall httpd
Removing Packages
# Remove package
yum remove httpd
dnf remove httpd
# Remove package and dependencies (not needed by other packages)
yum autoremove httpd
dnf autoremove httpd
# Remove all unused dependencies
yum autoremove
dnf autoremove
Updating Packages
# Update all packages
yum update
dnf update
# Update specific package
yum update httpd
dnf update kernel
# Update without confirmation
yum update -y
dnf update -y
# Check for available updates without installing
yum check-update
dnf check-update
# Update only security patches
yum update --security
dnf update --security
# Exclude specific packages from update
yum update --exclude=kernel*
dnf update --exclude=postgresql*
Searching and Querying Packages
Search for Packages
# Search by package name
yum search httpd
dnf search nginx
# Search in package description too
yum search all webserver
dnf search all database
# Case-insensitive search
yum search -i HTTPD
dnf search -i NGINX
Get Package Information
# Display package details
yum info httpd
dnf info nginx
# Show information for all versions
yum info --showduplicates httpd
dnf info --showduplicates kernel
# List package dependencies
yum deplist httpd
dnf repoquery --requires httpd
# Find what package provides a file
yum provides /usr/sbin/httpd
dnf provides */bin/python3
# Check if package is installed
yum list installed httpd
dnf list installed nginx
List Packages
# List all installed packages
yum list installed
dnf list installed
# List available packages
yum list available
dnf list available
# List all packages (installed and available)
yum list all
dnf list all
# List packages from specific repository
yum list --disablerepo="*" --enablerepo="epel"
dnf repository-packages epel list
# List recently added packages
yum list recent
dnf list recent
# List obsoleted packages
yum list obsoletes
dnf list obsoletes
Package Groups
Working with Group Packages
# List available package groups
yum grouplist
dnf grouplist
# Show group information
yum groupinfo "Development Tools"
dnf groupinfo "Development Tools"
# Install package group
yum groupinstall "Development Tools"
dnf groupinstall "Web Server"
# Remove package group
yum groupremove "Development Tools"
dnf groupremove "Web Server"
# Update package group
yum groupupdate "System Tools"
dnf groupupdate "System Tools"
Common Package Groups
# Essential development tools
yum groupinstall "Development Tools"
# Web server packages
yum groupinstall "Web Server"
# Graphical desktop
yum groupinstall "GNOME Desktop"
yum groupinstall "Server with GUI"
# System administration tools
yum groupinstall "System Administration Tools"
# Virtualization
yum groupinstall "Virtualization Host"
Repository Management
List Repositories
# List enabled repositories
yum repolist
dnf repolist
# List all repositories (enabled and disabled)
yum repolist all
dnf repolist --all
# Show detailed repository information
yum repolist -v
dnf repolist -v
# List disabled repositories only
yum repolist disabled
dnf repolist --disabled
Enable/Disable Repositories
# Enable repository temporarily (one command)
yum install --enablerepo=epel package-name
dnf install --enablerepo=powertools package-name
# Disable repository temporarily
yum update --disablerepo=epel
dnf update --disablerepo=appstream
# Enable repository permanently
yum-config-manager --enable epel
dnf config-manager --set-enabled powertools
# Disable repository permanently
yum-config-manager --disable epel
dnf config-manager --set-disabled crb
# Disable all repos except one
yum update --disablerepo="*" --enablerepo="rhel-8-baseos"
Add New Repositories
# Add repository from URL
yum-config-manager --add-repo https://example.com/repo.repo
dnf config-manager --add-repo https://example.com/repo.repo
# Install EPEL repository
yum install epel-release
dnf install epel-release
# Add RPM Fusion (Fedora)
dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
Cache Management
# Clean all cached data
yum clean all
dnf clean all
# Clean only package cache
yum clean packages
dnf clean packages
# Clean metadata cache
yum clean metadata
dnf clean metadata
# Rebuild cache
yum makecache
dnf makecache
# Show cache location
yum clean all && ls /var/cache/yum
dnf clean all && ls /var/cache/dnf
Transaction History
View History
# Show transaction history
yum history
dnf history
# Show specific transaction details
yum history info 5
dnf history info 5
# List transactions in date range
yum history list all
dnf history list --reverse
# Show summary of transaction
yum history summary
dnf history summary
Undo/Redo Transactions
# Undo last transaction
yum history undo last
dnf history undo last
# Undo specific transaction by ID
yum history undo 5
dnf history undo 5
# Redo transaction
yum history redo 5
dnf history redo 5
# Rollback to specific transaction
yum history rollback 10
dnf history rollback 10
Security Updates
List Security Updates
# List all security updates
yum updateinfo list security
dnf updateinfo list --security
# List critical security updates
yum updateinfo list sec-severity:Critical
dnf updateinfo --sec-severity=Critical
# List updates for specific CVE
yum updateinfo list cve CVE-2024-1234
dnf updateinfo list --cve CVE-2024-1234
Apply Security Updates
# Apply all security updates
yum update --security
dnf update --security
# Apply specific advisory (RHSA)
yum update --advisory=RHSA-2024:1234
dnf update --advisory=RHSA-2024:1234
# Apply updates for CVE
yum update --cve=CVE-2024-1234
dnf update --cve=CVE-2024-1234
# Apply only critical security updates
yum update --sec-severity=Critical
dnf update --sec-severity=Critical
Download Packages Without Installing
Download Only
# Download package without installing (yum)
yumdownloader httpd
# Download with dependencies
yumdownloader --resolve --destdir=/tmp/rpms httpd
# Download using dnf
dnf download httpd
# Download with dependencies (dnf)
dnf download --resolve --destdir=/tmp/rpms nginx
# Download specific version
yumdownloader httpd-2.4.6-97
dnf download httpd-2.4.51-7
Download Updates
# Download all available updates
yumdownloader --resolve $(yum list updates | awk 'NR>1 {print $1}')
# Using dnf
dnf download --resolve $(dnf list updates | tail -n +2 | awk '{print $1}')
Dependency Management
Check Dependencies
# Show package dependencies
yum deplist httpd
dnf repoquery --requires httpd
# Find what depends on a package
yum deplist --installed | grep package-name
dnf repoquery --whatrequires httpd
# Check for broken dependencies
yum check
dnf check
Resolve Dependency Issues
# Install missing dependencies
yum install package-name --skip-broken
dnf install package-name --skip-broken
# Fix broken dependencies
yum-complete-transaction
dnf distro-sync
Advanced Commands
Downgrade Packages
# Downgrade to previous version
yum downgrade httpd
dnf downgrade nginx
# Downgrade to specific version
yum downgrade httpd-2.4.6-90
dnf downgrade kernel-4.18.0-305
Lock Package Versions (Prevent Updates)
# Install versionlock plugin
yum install yum-plugin-versionlock
dnf install python3-dnf-plugin-versionlock
# Lock specific package version
yum versionlock add httpd
dnf versionlock add nginx
# List locked packages
yum versionlock list
dnf versionlock list
# Remove version lock
yum versionlock delete httpd
dnf versionlock delete nginx
# Clear all locks
yum versionlock clear
dnf versionlock clear
Show Changelog
# Display package changelog
yum changelog httpd
dnf changelog kernel
# Show changelog since date
yum changelog --since=2024-01-01 httpd
dnf changelog --since=2024-01-01 nginx
Debugging and Troubleshooting
Verbose Output
# Show detailed information
yum -v install httpd
dnf -v install nginx
# Show very detailed debug output
yum -d 10 -e 10 install httpd
dnf -vv install nginx
Check System
# Verify package installation
rpm -V httpd
rpm -qa --verify
# Check for problems
yum check
dnf check
# Verify repository metadata
yum repolist -v
dnf repolist -v
Performance Optimization
Speed Up Operations
# Use fastest mirror plugin (yum)
yum install yum-plugin-fastestmirror
# Enable parallel downloads (dnf)
echo "max_parallel_downloads=10" >> /etc/dnf/dnf.conf
# Disable delta RPMs (faster but more bandwidth)
echo "deltarpm=0" >> /etc/yum.conf # yum
echo "deltarpm=false" >> /etc/dnf/dnf.conf # dnf
Common Use Cases
System Maintenance
# Full system update
yum update -y && yum clean all
dnf update -y && dnf clean all
# Update and remove old kernels (keep last 2)
package-cleanup --oldkernels --count=2 # yum
dnf remove --oldinstallonly --setopt installonly_limit=2 kernel # dnf
# Check and fix issues
yum check && yum update -y
dnf check && dnf update -y
Find and Install Files
# Find which package provides a file
yum provides */semanage
dnf provides */htop
# Install package that provides command
yum install $(yum provides */semanage | head -1 | awk '{print $1}')
dnf install /usr/bin/htop
Frequently Asked Questions
What’s the difference between yum update and yum upgrade?
In yum, “update” and “upgrade” are identical – both update all packages to latest versions. In dnf, “upgrade” is the preferred command (though “update” still works as alias). Both commands update installed packages, remove obsolete packages, and install dependencies. There’s no functional difference in Red Hat systems.
How do I prevent a specific package from being updated?
Use the versionlock plugin: “yum install yum-plugin-versionlock” then “yum versionlock add package-name”. This prevents the package from being updated during “yum update”. Alternatively, use “–exclude=package-name” flag when running update commands, or add “exclude=package-name” to /etc/yum.conf for permanent exclusion.
Can I use yum commands on RHEL 8/9 systems?
Yes! RHEL 8/9 provide yum as a symbolic link to dnf for backward compatibility. When you type “yum”, it actually runs dnf. All your familiar yum commands work identically. The underlying system uses dnf, but you can continue using “yum” if preferred.
How do I install packages from EPEL repository?
First install the EPEL repository: “yum install epel-release” or “dnf install epel-release”. Then install packages normally: “yum install package-name”. EPEL (Extra Packages for Enterprise Linux) provides additional packages not in standard RHEL repositories. It’s safe and widely used in enterprise environments.
What does “yum clean all” do and when should I use it?
“yum clean all” removes cached package files, metadata, and headers from /var/cache/yum. Use it when: repository URLs change, you encounter metadata errors, disk space is low, or after modifying repository configurations. After cleaning, yum rebuilds cache on next operation. It’s safe and often fixes repository-related issues.
How do I list all files installed by a package?
Use rpm, not yum: “rpm -ql package-name” lists all files. For example, “rpm -ql httpd” shows every file installed by the httpd package including binaries, configuration files, and documentation. To find which package owns a specific file, use “rpm -qf /path/to/file”.
Can I download packages for offline installation?
Yes, use “yumdownloader –resolve –destdir=/tmp/rpms package-name” to download package and dependencies. Transfer the /tmp/rpms directory to offline system, then install with “yum localinstall /tmp/rpms/*.rpm” or “dnf install /tmp/rpms/*.rpm”. For full repository mirrors, use “reposync” command.
How do I rollback a package to previous version?
Use “yum history” to see transaction IDs, then “yum history undo ID” to rollback that transaction. Alternatively, “yum downgrade package-name” installs the previous version from repository. If old version not in repository, you’ll need the old RPM file: “yum downgrade package.rpm”.
What’s the difference between yum remove and yum autoremove?
“yum remove package” removes only the specified package, leaving dependencies. “yum autoremove package” removes the package AND any dependencies installed with it that aren’t needed by other packages. Running “yum autoremove” without package name removes all orphaned dependencies system-wide, freeing disk space.
How do I check which repository a package comes from?
Use “yum info package-name” and look at the “Repository” or “From repo” line. For installed packages: “yum list installed package-name” shows source repository. To see all packages from specific repository: “yum repository-packages reponame list” or “dnf repository-packages reponame list”.
Conclusion
Mastering yum and dnf commands is essential for effective Red Hat-based Linux system administration. From basic package installation and updates to advanced repository management and security patching, these package managers provide comprehensive tools for maintaining secure, up-to-date enterprise Linux environments. Whether managing RHEL, CentOS, AlmaLinux, Rocky Linux, or Fedora systems, the commands in this guide cover the full spectrum of package management tasks you’ll encounter in production environments.
For Red Hat subscription management and repository configuration, see our Complete Red Hat Subscription Management Guide.
Was this article helpful?