Skip to content
How to Build a Fast Local Yum Repository on CentOS and Switch to Domestic Mirrors
Operations 10 min read

How to Build a Fast Local Yum Repository on CentOS and Switch to Domestic Mirrors

This guide walks through creating a local CentOS Yum repository from an ISO image, backing up the default repo files, mounting the ISO, configuring a local repo, switching to Aliyun or 163 mirrors, setting repository priorities with yum‑plugin‑priorities, and testing package installation to ensure the local source is used first.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations

1. View the default Yum repository files

# ll /etc/yum.repos.d/

2. (Optional) Backup the existing Yum repository files

# mkdir /opt/centos-yum.bak
# mv /etc/yum.repos.d/* /opt/centos-yum.bak/

3. Mount the CentOS ISO image in the virtual machine

# mount -t iso9660 /dev/sr0 /opt/centos

4. Create a repo file that points to the mounted ISO

# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0

5. Clean the Yum cache and rebuild it

# yum clean all
# yum makecache

6. Replace the default repo with the Aliyun mirror

Download the appropriate Aliyun repo file for your CentOS version and overwrite the existing CentOS-Base.repo:

# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# yum clean all
# yum makecache

7. Replace the default repo with the 163 mirror

Download the 163 repo file for your CentOS version:

# wget -O /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
# yum clean all
# yum makecache

8. Set repository priority so the local repo is preferred

Install the priority plugin and configure it:

# yum -y install yum-plugin-priorities.noarch
# cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1

Add priority=1 to the local repo (lower numbers mean higher priority):

# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
priority=1

9. Test package installation before and after setting priority

Before priority (using Aliyun repo):

# yum -y install vim
# ... package is pulled from the "updates" repository

After priority (using local repo):

# yum -y install vim
# ... package and all dependencies are resolved from the "local" repository

These steps provide a fast, offline Yum source and ensure it is used preferentially over external mirrors.

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.

LinuxCentOSYUMlocal repository163 MirrorAliyun Mirroryum-plugin-priorities
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.