Ultimate YUM Cheat Sheet: Complete Command Guide for Linux System Admins

Ultimate YUM Package Manager Cheat Sheet: Complete Command Reference Guide

YUM (Yellowdog Updater Modified) is a powerful package management system used in Red Hat Enterprise Linux (RHEL), CentOS, Fedora, and other RPM-based Linux distributions. This comprehensive cheat sheet provides essential YUM commands with practical examples to help system administrators and Linux users efficiently manage packages, repositories, and system updates.

Whether you’re a beginner learning Linux package management or an experienced administrator looking for a quick reference, this guide covers everything from basic installation commands to advanced troubleshooting techniques.

Basic YUM Package Operations

Installing Packages

Install single or multiple packages with these essential commands:

# Install a single package
yum install package_name

# Install multiple packages
yum install package1 package2 package3

# Install package with automatic yes to prompts
yum install -y package_name

# Install package from specific repository
yum install --enablerepo=repository_name package_name

# Install local RPM package
yum localinstall package.rpm

# Install package group
yum groupinstall "Development Tools"

Removing Packages

Remove packages and their dependencies safely:

# Remove a single package
yum remove package_name

# Remove multiple packages
yum remove package1 package2 package3

# Remove package with automatic yes
yum remove -y package_name

# Remove package and dependencies
yum autoremove package_name

# Remove package group
yum groupremove "Development Tools"

Updating Packages

Keep your system updated with these commands:

# Update all packages
yum update

# Update specific package
yum update package_name

# Update multiple packages
yum update package1 package2

# Check for available updates
yum check-update

# Update with automatic yes
yum update -y

# Update system kernel
yum update kernel

# Downgrade a package
yum downgrade package_name

Package Information and Search

Searching for Packages

Find packages using various search methods:

# Search package by name
yum search package_name

# Search in package names and descriptions
yum search keyword

# Search for packages containing specific file
yum provides /path/to/file

# Search for packages by pattern
yum search "*keyword*"

# List all available packages
yum list available

# List installed packages
yum list installed

# List packages starting with specific name
yum list "package_name*"

Package Information

Get detailed information about packages:

# Display package information
yum info package_name

# Show package dependencies
yum deplist package_name

# Display package changelog
yum changelog package_name

# Show which package provides a file
yum whatprovides filename

# List files in an installed package
rpm -ql package_name

# Show package summary
yum info installed package_name

Repository Management

Repository Operations

Manage YUM repositories effectively:

# List enabled repositories
yum repolist

# List all repositories (enabled and disabled)
yum repolist all

# Enable a repository
yum-config-manager --enable repository_name

# Disable a repository
yum-config-manager --disable repository_name

# Add new repository
yum-config-manager --add-repo repository_url

# Install package from specific repo
yum --enablerepo=repo_name install package_name

# Clean repository cache
yum clean all

Repository Configuration

Configure and manage repository settings:

# View repository configuration
cat /etc/yum.repos.d/repository_name.repo

# Create custom repository file
vi /etc/yum.repos.d/custom.repo

# Verify repository GPG keys
rpm --import /path/to/gpg-key

# Update repository metadata
yum makecache

# Rebuild repository cache
yum makecache fast

System Maintenance Commands

Cache Management

Manage YUM cache for optimal performance:

# Clean package cache
yum clean packages

# Clean repository metadata
yum clean metadata

# Clean all cache data
yum clean all

# Clean expired cache
yum clean expire-cache

# Clean repository database
yum clean dbcache

# Build cache for enabled repositories
yum makecache

History and Logs

Track package management history:

# View YUM transaction history
yum history

# Show detailed history for transaction ID
yum history info transaction_id

# Undo a specific transaction
yum history undo transaction_id

# Redo a specific transaction
yum history redo transaction_id

# List history summary
yum history summary

# View YUM logs
tail -f /var/log/yum.log

Advanced YUM Operations

Dependency Management

Handle package dependencies with precision:

# Check package dependencies
yum deplist package_name

# Install dependencies only
yum-builddep package.src.rpm

# Skip dependency checks (use with caution)
yum install --skip-broken package_name

# Fix broken dependencies
yum check

# Install package ignoring conflicts
yum install --nobest package_name

Package Groups

Manage collections of related packages:

# List available package groups
yum grouplist

# Install package group
yum groupinstall "Group Name"

# Remove package group
yum groupremove "Group Name"

# Update package group
yum groupupdate "Group Name"

# Show group information
yum groupinfo "Group Name"

# List hidden groups
yum grouplist hidden

Version and Architecture Management

Handle specific package versions and architectures:

# Install specific version
yum install package_name-version

# List available versions
yum --showduplicates list package_name

# Install 32-bit package on 64-bit system
yum install package_name.i386

# Exclude specific packages from updates
yum update --exclude=package_name

# Set permanent package exclusions
echo "exclude=package_name" >> /etc/yum.conf

Troubleshooting and Diagnostics

Common Issues Resolution

Resolve typical YUM problems:

# Fix corrupted RPM database
rpm --rebuilddb

# Clear all YUM cache
yum clean all && yum makecache

# Fix broken dependencies
yum check
yum-complete-transaction

# Resolve conflicting packages
yum remove conflicting_package
yum install desired_package

# Fix GPG key issues
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-*

# Repair damaged YUM database
yum check-update

Debugging Commands

Debug YUM operations with verbose output:

# Run YUM with debug output
yum -d 10 install package_name

# Enable verbose mode
yum -v install package_name

# Test run without making changes
yum --assumeno install package_name

# Show what would be done
yum install --downloadonly package_name

# Check for problems
yum check all

YUM Configuration and Customization

Configuration Files

Customize YUM behavior through configuration:

# Main YUM configuration
/etc/yum.conf

# Repository definitions
/etc/yum.repos.d/

# YUM variables
/etc/yum/vars/

# Plugin configuration
/etc/yum/pluginconf.d/

Useful Configuration Options

Common YUM configuration parameters:

# /etc/yum.conf example settings
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
exclude=kernel* php*
timeout=120
retries=5

Security and GPG Operations

GPG Key Management

Handle repository security keys:

# Import GPG key
rpm --import gpg-key-file

# List imported GPG keys
rpm -qa gpg-pubkey*

# Verify package signature
rpm --checksig package.rpm

# Import key from URL
rpm --import https://example.com/gpg-key

# Check GPG key details
rpm -qi gpg-pubkey-keyid

Security Updates

Focus on security-related updates:

# Install security updates only
yum update --security

# List available security updates
yum updateinfo list security

# Show security advisory details
yum updateinfo info advisory_id

# Update specific CVE
yum update --cve CVE-YYYY-NNNN

Performance Optimization

Speed Enhancement

Optimize YUM performance:

# Use fastest mirror plugin
yum install yum-plugin-fastestmirror

# Enable parallel downloads
echo "max_parallel_downloads=10" >> /etc/yum.conf

# Use delta RPMs
yum install deltarpm
echo "deltarpm=1" >> /etc/yum.conf

# Set connection timeout
echo "timeout=30" >> /etc/yum.conf

# Enable keepcache for downloaded packages
echo "keepcache=1" >> /etc/yum.conf

Bandwidth Management

Control bandwidth usage during package operations:

# Limit download speed (KB/s)
echo "throttle=100k" >> /etc/yum.conf

# Set bandwidth limit per connection
echo "minrate=1000" >> /etc/yum.conf

# Configure connection attempts
echo "retries=3" >> /etc/yum.conf

Backup and Recovery

Package List Backup

Create backups of installed packages:

# Create package list backup
rpm -qa > /backup/installed-packages.txt

# Create detailed package backup
yum list installed > /backup/yum-installed.txt

# Backup YUM configuration
cp -r /etc/yum* /backup/

# Restore packages from list
yum install $(cat /backup/installed-packages.txt)

Transaction Backup

Save and restore YUM transactions:

# Save transaction
yum shell
> transaction save filename
> quit

# Load saved transaction
yum shell
> transaction load filename
> run
> quit

Network and Proxy Configuration

Proxy Settings

Configure YUM to work through proxy servers:

# Configure proxy in /etc/yum.conf
proxy=http://proxy.example.com:8080
proxy_username=username
proxy_password=password

# Set proxy authentication
proxy_auth_method=basic

# Bypass proxy for specific hosts
proxy_exclude=localhost,127.0.0.1,.local

Network Troubleshooting

Resolve network-related YUM issues:

# Test repository connectivity
curl -I repository_baseurl

# Check DNS resolution
nslookup repository_hostname

# Verify firewall settings
iptables -L | grep -i drop

# Test with verbose curl
curl -v repository_url

Automation and Scripting

Automated Package Management

Automate YUM operations in scripts:

# Install packages automatically
yum install -y package_name

# Update system silently
yum update -y --quiet

# Check if package is installed
rpm -q package_name || yum install -y package_name

# Conditional package installation
if ! rpm -q package_name; then
    yum install -y package_name
fi

Cron Job Examples

Schedule automatic maintenance tasks:

# Daily security updates (crontab -e)
0 2 * * * yum update -y --security

# Weekly full system update
0 3 * * 0 yum update -y

# Clean cache weekly
0 4 * * 0 yum clean all

Migration to DNF

YUM to DNF Transition

Prepare for migration from YUM to DNF:

# Install DNF (where available)
yum install dnf

# DNF equivalent commands
dnf install package_name    # Same as yum install
dnf remove package_name     # Same as yum remove
dnf update                  # Same as yum update
dnf search keyword          # Same as yum search
dnf info package_name       # Same as yum info

# Create YUM alias for DNF
alias yum='dnf'

Quick Reference Table

Task YUM Command Description
Install package yum install package_name Install a single package
Remove package yum remove package_name Remove a package
Update system yum update Update all packages
Search packages yum search keyword Search for packages
List installed yum list installed Show installed packages
Package info yum info package_name Display package details
Clean cache yum clean all Clean all cache data
List repos yum repolist Show enabled repositories
View history yum history Show transaction history
Install group yum groupinstall "Group Name" Install package group

Common Use Cases and Examples

Web Server Setup

Install and configure a web server using YUM:

# Install Apache web server
yum install -y httpd

# Install PHP and modules
yum install -y php php-mysql php-gd

# Install database server
yum install -y mariadb-server mariadb

# Start and enable services
systemctl start httpd mariadb
systemctl enable httpd mariadb

Development Environment

Set up a development environment:

# Install development tools
yum groupinstall -y "Development Tools"

# Install version control
yum install -y git subversion

# Install programming languages
yum install -y python3 nodejs npm

# Install text editors
yum install -y vim nano emacs

System Monitoring Tools

Install monitoring and diagnostic tools:

# Install monitoring tools
yum install -y htop iotop nethogs

# Install network tools
yum install -y nmap wireshark tcpdump

# Install system analysis tools
yum install -y strace lsof sysstat

Best Practices and Tips

Security Best Practices

  • Always verify GPG signatures: Keep gpgcheck=1 in configuration
  • Use official repositories: Avoid untrusted third-party repos
  • Regular updates: Schedule security updates automatically
  • Backup before major changes: Create system snapshots
  • Review changes: Check what will be installed/updated

Performance Tips

  • Enable fastest mirror: Install yum-plugin-fastestmirror
  • Use local mirrors: Configure nearby repository mirrors
  • Clean cache regularly: Prevent disk space issues
  • Enable delta RPMs: Reduce download sizes
  • Parallel downloads: Set max_parallel_downloads

Troubleshooting Guidelines

  • Check connectivity: Verify internet and repository access
  • Clear cache: Clean YUM cache when facing issues
  • Verify disk space: Ensure sufficient space for operations
  • Check logs: Review /var/log/yum.log for errors
  • Rebuild database: Use rpm –rebuilddb for corruption

Conclusion

This comprehensive YUM cheat sheet covers essential commands and techniques for effective package management in RPM-based Linux distributions. From basic installation and removal operations to advanced troubleshooting and automation, these commands will help you maintain and manage your Linux systems efficiently.

Remember to always test commands in a safe environment before applying them to production systems. Regular practice with these commands will make you proficient in Linux package management and system administration.

Keep this cheat sheet handy as a quick reference guide, and consider creating your own customized version based on your specific use cases and requirements. As you become more experienced with YUM, you’ll discover additional techniques and optimizations that work best for your environment.

Whether you’re managing a single server or a large infrastructure, mastering YUM package management is crucial for maintaining secure, updated, and well-functioning Linux systems.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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