For our Blog Visitor only Get Additional 3 Month Free + 10% OFF on TriAnnual Plan YSBLOG10
Grab the Deal

How to Optimize YUM on Linux Server

To optimize YUM on a Linux server, enable the fastest mirror selection, tune caching and metadata settings, clean and rebuild YUM data regularly, disable slow or unused repositories, use delta RPMs, and automate off-peak updates. For fleets, add a local mirror or caching proxy. On RHEL 8/9 derivatives, use the equivalent DNF options.

Managing updates should be fast, consistent, and safe. In this guide, you’ll learn how to optimize YUM on Linux servers for quicker installs and updates, predictable performance, and fewer repo-related errors—based on years of managing CentOS/RHEL systems in production hosting environments. Where applicable, I’ll also map settings to DNF for newer distributions.

What Is YUM and Why Optimization Matters

YUM (Yellowdog Updater, Modified) is the package manager used on CentOS/RHEL 7 and older. It resolves dependencies, pulls metadata, and downloads packages from multiple repositories. Without tuning, YUM can feel slow due to network latency, overly chatty repositories, or bloated metadata. Proper optimization saves time, bandwidth, and reduces update failures.

Quick Wins: A 5-Minute YUM Speed Checklist

  • Enable the fastest mirror plugin and keep plugins on.
  • Clean and rebuild YUM cache and RPM database.
  • Disable slow or unused third‑party repos by default.
  • Keep packages cached for reuse (especially on build servers).
  • Automate updates off‑peak with yum-cron and lock down GPG checks.

Prerequisites and Notes

  • Applies to CentOS/RHEL 6/7 and compatible forks still using YUM.
  • For RHEL/AlmaLinux/Rocky 8+ (DNF), see the DNF mapping section below.
  • Run commands as root or with sudo.
  • Back up repo files in /etc/yum.repos.d/ before editing.

Step 1: Enable and Tune Core YUM Settings

Edit /etc/yum.conf for Performance

These settings reduce unnecessary downloads, avoid stalls, and keep YUM responsive under normal network conditions.

sudo cp /etc/yum.conf /etc/yum.conf.bak
sudo vi /etc/yum.conf

[main]
plugins=1
keepcache=1
metadata_expire=6h
# Network tuning (adjust to your environment)
timeout=30
retries=3
minrate=200k
# If IPv6 is flaky in your DC:
# ip_resolve=4
# Install faster by skipping docs in minimal images
tsflags=nodocs
# Security
gpgcheck=1

Explanation:

  • plugins=1 ensures YUM can use performance and security plugins.
  • keepcache=1 helps when multiple servers reuse packages (build/release hosts).
  • metadata_expire=6h balances freshness with fewer metadata fetches.
  • timeout/minrate/retries reduce slow-hanging sessions.
  • tsflags=nodocs cuts install time and disk usage on minimal hosts.
  • gpgcheck=1 keeps signature verification on for security (recommended).

Enable the Fastest Mirror Plugin

Fastestmirror selects the nearest/fastest mirror automatically, reducing download time significantly.

# Install plugins if missing
sudo yum install -y yum-plugin-fastestmirror yum-utils

# Ensure the plugin is enabled
sudo sed -i 's/^enabled=.*/enabled=1/' /etc/yum/pluginconf.d/fastestmirror.conf

# Optional: clear and rebuild cache
sudo yum clean all
sudo yum makecache fast

On many CentOS/RHEL 7 builds, fastestmirror is installed by default but may not be enabled. Keeping it on is one of the biggest speed wins.

Step 2: Optimize Repositories (The Biggest Real‑World Bottleneck)

Disable Slow or Unused Repos by Default

Every enabled repo adds metadata fetches and dependency checks. Disable what you don’t need and enable only when required.

# List repos and status
yum repolist all

# Disable a repo
sudo yum-config-manager --disable some-thirdparty

# Enable only when needed
sudo yum --enablerepo=some-thirdparty install package-name

For flaky sources, add skip_if_unavailable=1 in their .repo files to prevent YUM from stalling when that repo is down.

sudo vi /etc/yum.repos.d/some-thirdparty.repo

[some-thirdparty]
name=Third-party Repo
baseurl=http://mirror.example/repo/
enabled=0
gpgcheck=1
skip_if_unavailable=1

Use Reliable Mirrors and Prefer Baseurl Over Mirrorlist (When Needed)

If mirrorlist is inconsistent in your region, choose a stable, known-fast baseurl. This cuts redirection overhead and flakiness.

For enterprise fleets, standardize the same mirror across servers to maximize cache hits and predictability.

Repository Priorities to Reduce Dependency Conflicts

Setting priorities ensures core OS repos outrank third-party ones, reducing conflict resolution time and surprises.

# Install priorities plugin
sudo yum install -y yum-plugin-priorities

# In each .repo file, add a lower number = higher priority
sudo vi /etc/yum.repos.d/CentOS-Base.repo
priority=1

sudo vi /etc/yum.repos.d/epel.repo
priority=10

Step 3: Speed Up Downloads and Reduce Bandwidth

Enable Delta RPMs (When CPU Is Not a Bottleneck)

Delta RPMs download only differences between versions, saving bandwidth at the cost of some CPU to reconstruct packages. Great on constrained links; optional in CPU-limited VMs.

sudo yum install -y deltarpm yum-plugin-deltarpm

# In /etc/yum.conf
deltarpm=1

Cache Aggressively on Build/CI Hosts

For build servers and golden-image pipelines, keepcache=1 prevents re-downloading packages repeatedly. Combine with a local repository or caching proxy for maximum savings.

Throttle and Minrate

Use minrate to fail fast on underperforming mirrors, and throttle only when you need to preserve bandwidth for other workloads.

# In /etc/yum.conf
minrate=200k
# throttle=0 (no limit) or set a value like 1M to cap bandwidth
# throttle=1M

Step 4: Automate Updates Off‑Peak

Automating routine refreshes and updates reduces latency during work hours and keeps metadata warm.

# Install and enable automatic update tools
sudo yum install -y yum-cron
sudo systemctl enable --now yum-cron

# Configure security-only or full updates
sudo vi /etc/yum/yum-cron.conf
apply_updates = yes
download_updates = yes
# Consider security update filters based on your policy

Schedule heavy updates during low-traffic windows. In managed environments, providers like YouStable can configure maintenance windows and test updates on staging first.

Step 5: Maintenance and Troubleshooting for Long‑Lived Hosts

Clean and Rebuild YUM Data

Over time, caches and RPM databases can bloat or become inconsistent, slowing down dependency resolution.

# Clean everything and rebuild cache
sudo yum clean all
sudo rm -rf /var/cache/yum
sudo yum makecache fast

# Rebuild RPM database if dependency resolution is slow or errors occur
sudo rpm --rebuilddb

Fix Incomplete Transactions and Locks

# If a previous run was interrupted:
sudo yum-complete-transaction

# If a lock remains, identify the process
sudo lsof /var/run/yum.pid
# Or simply wait/kill responsibly, then retry

Step 6: Centralize with a Local Mirror or Caching Proxy

For dozens or hundreds of servers, nothing beats a local mirror or caching proxy. It eliminates WAN latency and maximizes cache hits.

  • Lightweight caching: Squid or Nginx reverse proxy in front of upstream mirrors.
  • Full mirrors: reposync + createrepo to host your own mirror of Base/EPEL.
  • Enterprise repo managers: Pulp, Sonatype Nexus, or Artifactory for version pinning and access control.
# Example: local mirror with reposync (run on mirror host)
sudo yum install -y yum-utils createrepo
sudo reposync -p /var/www/html/repos/ -r base -r updates -r extras
sudo createrepo /var/www/html/repos/base
# Then point clients' baseurl to http://your-mirror/repos/base/

YouStable’s managed server team can set up a private mirror and enforce consistent repo policies across your fleet to stabilize and speed up patching.

Security Best Practices While Optimizing

  • Keep gpgcheck=1 for all repos and verify GPG keys are correct and current.
  • Restrict or audit third‑party repos; use priorities and enable on demand.
  • Use HTTPS mirrors where available; pin trusted baseurls.
  • Log updates: monitor /var/log/yum.log for anomalies and performance trends.

DNF Equivalents for RHEL 8/9, AlmaLinux, Rocky

Modern distributions replaced YUM with DNF. Most optimizations still apply with slightly different options.

  • Fastest mirror: fastestmirror=true in /etc/dnf/dnf.conf
  • Parallel downloads: max_parallel_downloads=10 (DNF only)
  • Metadata sync: metadata_timer_sync=3600
  • Delta RPMs: deltarpm=true (default on many builds)
  • Keep cache: keepcache=True
sudo cp /etc/dnf/dnf.conf /etc/dnf/dnf.conf.bak
sudo vi /etc/dnf/dnf.conf

[main]
fastestmirror=True
max_parallel_downloads=10
metadata_timer_sync=3600
keepcache=True
deltarpm=True

Real‑World Scenarios and Tips

  • CI/CD pipelines: keepcache=1 and a local mirror cut build times drastically.
  • Remote branches/offices: use a site-local caching proxy to avoid WAN dependency.
  • Air‑gapped servers: mirror repos internally with reposync and sign your metadata.
  • Minimal containers: tsflags=nodocs to speed up image layers and save space.
  • Flaky IPv6 networks: set ip_resolve=4 until network reliability improves.

Optimization Checklist (Copy/Paste)

  • plugins=1, fastestmirror enabled, gpgcheck=1
  • keepcache=1, metadata_expire=6h
  • timeout=30, retries=3, minrate=200k
  • Disable unused repos; set priorities; skip_if_unavailable=1
  • Enable deltarpm when bandwidth is precious
  • Automate with yum-cron during off‑peak hours
  • Regularly yum clean all; rpm –rebuilddb if needed
  • Consider a local mirror or caching proxy for fleets

Common Commands Reference

# Show enabled repos
yum repolist

# Clean and rebuild cache
yum clean all && yum makecache fast

# List fastest mirror plugin details
yum info yum-plugin-fastestmirror

# Disable/enable repos on demand
yum --disablerepo="*" --enablerepo="base,updates" list available

FAQs: How to Optimize YUM on Linux Server

What is the fastest way to speed up YUM immediately?

Enable the fastestmirror plugin, clean the cache, and disable slow or unused repositories. In many environments, those three steps deliver the biggest improvement with minimal risk.

Should I enable delta RPMs on all servers?

Enable delta RPMs when bandwidth is limited or expensive. If CPU is scarce or updates are infrequent, the overhead may not be worth it. Test both ways on a representative host and measure runtime and bandwidth.

Is it safe to increase metadata_expire to reduce refreshes?

Yes, within reason. Values like 6–24 hours are a good balance for most servers. For fast-moving repos or security-sensitive workloads, keep it lower and automate off-peak refreshes with yum-cron.

How do I handle a slow or failing repository without breaking updates?

Set skip_if_unavailable=1 in the repo file, lower its priority, and keep it disabled by default. Enable it only when you need that specific package. This prevents YUM from hanging when the repo misbehaves.

Is YUM still supported, or should I migrate to DNF?

YUM is maintained for CentOS/RHEL 7, but newer releases use DNF. If you’re planning an OS upgrade, map your YUM settings to DNF equivalents (fastestmirror, keepcache, max_parallel_downloads) to gain further speed and stability improvements.

Final word:

consistent, well-documented YUM settings save hours across a fleet. If you prefer a managed approach, YouStable can provision servers with optimized YUM/DNF defaults, private mirrors, and staged rollouts to keep your production environment fast, secure, and predictable.

Prahlad Prajapati

Prahlad is a web hosting specialist and SEO-focused organic growth expert from India. Active in the digital space since 2019, he helps people grow their websites through clean, sustainable strategies. Passionate about learning and adapting fast, he believes small details create big success. Discover his insights on web hosting and SEO to elevate your online presence.

Leave a Comment

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

Scroll to Top