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.
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.repo2. 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.noarch3. 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 mountResult of df -h shows the ISO is mounted at /mnt/mytest:
/dev/sr0 4.4G 4.4G 0 100% /mnt/mytestMake the mount permanent by adding a line to /etc/fstab:
echo "/dev/sr0 /mnt/mytest iso9660 defaults 0 0" >> /etc/fstabBackup existing repo files and create a new local.repo:
# cd /etc/yum.repos.d/
# mkdir repo_bak
# mv *.repo repo_bak/
# touch local.repoExample local.repo content:
[name]
name=my new repo
baseurl=file:///mnt/mytest
gpgcheck=0
enabled=14. 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.repoIf wget is missing, install it via the local YUM repository first:
# yum -y install wgetClean 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
105645. 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 commandCommon error: “Another program is locking yum; waiting for it to exit…”. Resolve by removing the lock file:
# rm -f /var/run/yum.pidAfter removing the lock, YUM commands run normally.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
