Operations 13 min read

Mastering YUM: Build Local & Network Repositories and Install Packages on CentOS

This guide walks you through YUM fundamentals, setting up a local CD‑ROM repository, configuring an Aliyun network mirror, and using common YUM commands—including installation, removal, updates, and troubleshooting lock‑file errors—on a CentOS system.

Open Source Linux
Open Source Linux
Open Source Linux
Mastering YUM: Build Local & Network Repositories and Install Packages on CentOS

1. Introduction to YUM

YUM is a package manager that automatically resolves dependencies when installing RPM packages from a repository.

YUM configuration files are usually located in /etc/yum.repos.d directory.

# cd /etc/yum.repos.d/
# ll
-rw-r--r--. 1 root root 1664 Sep 5 21:05 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Sep 5 21:05 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Sep 5 21:05 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Sep 5 21:05 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Sep 5 21:05 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Sep 5 21:05 CentOS-Sources.repo
-rw-r--r--. 1 root root 6639 Sep 5 21:05 CentOS-Vault.repo

2. Installing YUM

CentOS ships with YUM preinstalled. Verify the installed YUM packages:

# rpm -qa | grep yum
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-plugin-fastestmirror-1.1.31-52.el7.noarch
yum-3.4.3-163.el7.centos.noarch

3. Setting up a Local CD‑ROM YUM Repository

Mount the ISO image in a virtual machine and create a mount point:

mkdir /mnt/mytest
mount /dev/sr0 /mnt/mytest   # read‑only mount
df -h                         # verify mount

Result of df -h shows the ISO is mounted at /mnt/mytest:

/dev/sr0                 4.4G  4.4G     0  100% /mnt/mytest

Make the mount permanent by adding a line to /etc/fstab:

echo "/dev/sr0 /mnt/mytest iso9660 defaults 0 0" >> /etc/fstab

Backup existing repo files and create a new local.repo:

# cd /etc/yum.repos.d/
# mkdir repo_bak
# mv *.repo repo_bak/
# touch local.repo

Example local.repo content:

[name]
name=my new repo
baseurl=file:///mnt/mytest
gpgcheck=0
enabled=1

4. Configuring a Network YUM Repository (Aliyun Mirror)

Backup current repos, then download the appropriate Aliyun repo file for the system version:

# mkdir repo_bak
# mv *.repo repo_bak/
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

If wget is missing, install it via the local YUM repository first:

# yum -y install wget

Clean cache and rebuild the metadata:

# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
# yum makecache
# yum list | wc -l
10564

5. Using YUM

Basic syntax: yum [options] [command] [package…]. Common option -y answers “yes” to all prompts.

Typical commands:

# yum clean all                     # clear cache
# yum makecache                    # rebuild cache
# yum -y install httpd             # install Apache
# yum remove httpd                  # remove package
# yum update                       # update all packages
# yum list | grep httpd            # list installed/available httpd packages
# yum -y install wget && reboot    # install wget and reboot
# yum -y install net-tools         # install ifconfig
# yum -y install iputils           # install ping
# yum provides `which ifconfig`    # find which package provides a command

Common error: “Another program is locking yum; waiting for it to exit…”. Resolve by removing the lock file:

# rm -f /var/run/yum.pid

After removing the lock, YUM commands run normally.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxSystem Administrationpackage managementCentOSyumlocal repositorynetwork repository
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.