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

How to Setup YUM on Linux Server – Easy Guide

To set up YUM on a Linux server, verify YUM/DNF is installed, enable repositories, import GPG keys, update metadata, and test package operations. Configure /etc/yum.conf and /etc/yum.repos.d/*.repo, enable EPEL (if needed), add optional plugins (fastestmirror, priorities, versionlock), then update and secure your system with routine YUM commands.

YUM (Yellowdog Updater, Modified) is the classic package manager for RHEL/CentOS-based Linux servers. On RHEL 8/9 and derivatives (AlmaLinux, Rocky), DNF replaces YUM, but the yum command still works as a wrapper. This guide shows how to setup YUM on Linux servers properly, configure repositories, enable EPEL, and troubleshoot common issues—using production-ready best practices I’ve learned managing hosting fleets for 12+ years.

Prerequisites and Supported Distributions

YUM applies to RHEL/CentOS 6/7 and Amazon Linux 1/2. On RHEL 8/9 and modern derivatives, DNF is the backend but the yum command is available for compatibility. Ensure:

  • Root or sudo access
  • Working network/DNS and correct system time
  • RHEL systems registered with Red Hat Subscription Management (if applicable)
  • For offline/local repos: access to ISO or mirrored packages

Quick Start: Setup YUM in 5 Minutes

Use these commands to get YUM running fast on most RHEL/CentOS-like servers.

# 1) Check YUM/DNF presence
yum --version || dnf --version

# 2) RHEL only: register to enable repos
sudo subscription-manager register --auto-attach

# 3) Update package metadata and core tools
sudo yum clean all
sudo yum makecache
sudo yum update -y

# 4) Enable EPEL (RHEL/CentOS 7; for 8/9, use epel-release for your major version)
sudo yum install -y epel-release

# 5) Optional: speed and stability plugins
sudo yum install -y yum-plugin-fastestmirror yum-plugin-priorities
# If on DNF-based systems:
# sudo dnf install -y dnf-plugins-core

# 6) Test install/remove
sudo yum install -y htop
sudo yum remove -y htop

Understand YUM’s Core Files and Structure

  • /etc/yum.conf — global configuration (proxies, cache, exclusions)
  • /etc/yum.repos.d/*.repo — repository configuration files
  • /var/cache/yum/ — cache and metadata
  • GPG keys — used to verify package signatures (GPG integrity)

Configure YUM Repositories (Base, AppStream, EPEL, Third-Party)

Enable Official Repositories

On RHEL, you must register to access official repos:

sudo subscription-manager register --auto-attach
sudo subscription-manager refresh
sudo subscription-manager repos --list-enabled

On CentOS 7, base repositories are typically enabled by default when you install from a standard ISO. On Rocky/Alma (RHEL 8/9 family), the default enabled repos (BaseOS, AppStream, extras) come preconfigured.

Enable EPEL Repository

EPEL (Extra Packages for Enterprise Linux) offers many community packages often used on web hosting servers (htop, fail2ban, certbot, etc.).

# RHEL/CentOS 7 / Amazon Linux 2 (check availability)
sudo yum install -y epel-release

# RHEL 8/9, AlmaLinux 8/9, Rocky Linux 8/9
sudo dnf install -y epel-release
sudo dnf makecache

Add a Custom or Third-Party Repo

Create a .repo file under /etc/yum.repos.d/. Always keep gpgcheck=1 and provide a valid GPG key URL for security.

sudo tee /etc/yum.repos.d/custom.repo >/dev/null <<'EOF'
[custom-tools]
name=Custom Tools Repository
baseurl=https://repo.example.com/el/$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.example.com/keys/RPM-GPG-KEY-custom
priority=10
EOF

sudo yum clean all
sudo yum makecache

Essential YUM Commands You’ll Use Daily

Search, Info, and Listing

# Search for packages
yum search nginx

# Show package details
yum info nginx

# List installed packages
yum list installed

# List available packages from repos
yum list available

Install, Remove, and Update

# Install and remove
sudo yum install -y nginx
sudo yum remove -y nginx

# Update everything (use maintenance windows in production)
sudo yum update -y

# Update a single package
sudo yum update -y openssl

Groups and Utilities

# Discover software groups (e.g., "Development Tools")
yum group list

# Install group
sudo yum groupinstall -y "Development Tools"

# Clean and rebuild metadata
sudo yum clean all
sudo yum makecache fast

Advanced YUM Configuration (Security, Speed, Proxy, Local Repos)

Secure Package Verification with GPG

Keep gpgcheck=1 in repo files. If a repo requires manual key import:

# Import an RPM GPG key
sudo rpm --import https://repo.example.com/keys/RPM-GPG-KEY-custom

# Verify that the key was added
rpm -qa gpg-pubkey*

Configure Proxy and Core Options

For servers behind a proxy or to set global behaviors, edit /etc/yum.conf.

sudo cp /etc/yum.conf /etc/yum.conf.bak
sudo tee -a /etc/yum.conf >/dev/null <<'EOF'
# Global options
cachedir=/var/cache/yum
keepcache=0
exactarch=1
gpgcheck=1
# Proxy (uncomment if needed)
# proxy=http://proxy.example.com:3128
# proxy_username=myuser
# proxy_password=mypass
# Exclude sensitive packages from updates
exclude=kernel* centos-release* redhat-release*
EOF

Improve Speed and Stability

  • fastestmirror: Picks the fastest mirror automatically.
  • priorities: Prevents low-priority repos from overriding base packages.
  • versionlock: Locks critical package versions on production.
# Install plugins (YUM-based)
sudo yum install -y yum-plugin-fastestmirror yum-plugin-priorities yum-plugin-versionlock

# Lock a package version
sudo yum versionlock add openssl
# Remove lock
sudo yum versionlock delete openssl

Create a Local YUM Repo (ISO, Air‑Gapped, or Caching)

For offline servers or to guarantee deterministic builds, create a local repo. Example using an ISO or a directory with RPMs:

# Mount ISO and expose it as a repo
sudo mkdir -p /mnt/rhel
sudo mount -o loop /path/to/RHEL-8.iso /mnt/rhel

# Or use a local RPM directory
sudo mkdir -p /opt/localrepo
# Place *.rpm files inside /opt/localrepo

# Create repodata (createrepo or createrepo_c)
sudo yum install -y createrepo
sudo createrepo /opt/localrepo

# Add repo file
sudo tee /etc/yum.repos.d/local.repo >/dev/null <<'EOF'
[localrepo]
name=Local RPM Repository
baseurl=file:///opt/localrepo
enabled=1
gpgcheck=0
EOF

# Refresh and test
sudo yum clean all
sudo yum makecache
sudo yum list available --disablerepo="*" --enablerepo="localrepo"

DNF vs YUM: What Should You Use?

On RHEL 8/9, AlmaLinux, and Rocky Linux, DNF is the default. The yum command is a compatibility wrapper that maps to DNF. Use dnf for new automation but you can safely keep existing yum scripts. Most commands are identical in practice.

# Functionally equivalent on DNF-based systems
sudo dnf makecache
sudo dnf update -y
sudo dnf install -y nginx

Troubleshooting YUM: Common Errors and Fixes

“Cannot find a valid baseurl” or Timeout

  • Check DNS and network: ping 8.8.8.8, dig/curl a repo URL.
  • Ensure correct time (TLS requires valid time): sudo timedatectl set-ntp true.
  • Disable broken repos temporarily: yum –disablerepo=brokenrepo makecache.
  • On RHEL, verify subscription: subscription-manager status.

GPG Key Retrieval Failed

  • Import the correct GPG key: rpm –import URL or use gpgkey= in .repo.
  • Confirm gpgcheck=1 and that URLs are reachable via proxy if used.

Another App is Currently Holding the Yum Lock

  • Wait for other processes (cloud-init, auto-updaters) to finish.
  • Find process: lsof /var/run/yum.pid or ps aux | grep yum/dnf.
  • Avoid killing mid-transaction; if corrupted, use yum-complete-transaction (yum-utils).

Metadata Checksum Errors

  • Clear caches: yum clean all; yum makecache.
  • Switch mirrors or disable a specific repo temporarily.

Best Practices for Production Servers

  • Always snapshot or back up before mass updates.
  • Use maintenance windows and test updates on staging first.
  • Pin or lock critical packages (kernel, glibc, database drivers) using versionlock.
  • Configure priorities and avoid untrusted repos overriding base packages.
  • Enable automatic security updates only when validated in staging; otherwise patch manually with change control.

When Managed Help Saves Time

If you run mission-critical sites, consider managed infrastructure. At YouStable, our Managed VPS and Dedicated Servers on AlmaLinux/Rocky are delivered with secure YUM/DNF configuration, curated repositories, version locking, and scheduled patching—so you can focus on growth while we handle updates, rollbacks, and compliance.

FAQs: How to Setup YUM on Linux Server

How do I install YUM on a minimal Linux server?

On CentOS/RHEL 7, YUM is included. If missing, install via rpm from the installation media or use dnf on modern systems. Ensure python, rpm, and yum-utils are present. On RHEL 8/9, use dnf (yum is a wrapper) and install dnf-plugins-core for extra features.

How can I list enabled repositories in YUM?

yum repolist enabled
# or with DNF
dnf repolist enabled

How do I disable or enable a repo temporarily?

# Disable a repo for a single command
yum –disablerepo=epel update

# Enable a specific repo temporarily
yum –enablerepo=custom-tools install mypkg

Can I roll back a package with YUM?

Yes, if the previous RPM remains available. Use yum downgrade packagename. For complex rollbacks, maintain local mirrors or snapshots (LVM/ZFS/cloud snapshots) to guarantee availability. Production-grade rollbacks are easiest with snapshots and version locking.

Can I use YUM on Ubuntu or Debian?

No. Ubuntu/Debian use APT (apt, apt-get). YUM/DNF are for RHEL-based distributions. Use apt update, apt install, and apt sources list for those systems.

Final Thoughts

Setting up YUM on a Linux server involves enabling the right repositories, enforcing GPG verification, optimizing performance with plugins, and following disciplined update practices. With this foundation, you’ll install, update, and secure packages confidently. Need hands-off reliability? YouStable’s managed servers bake in these best practices from day one.

Alok Trivedi

Leave a Comment

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

Scroll to Top