How to Replace YUM Repositories with Domestic Mirrors on CentOS 7
This guide explains why the default CentOS 7 YUM repositories are slow for Chinese users and provides step‑by‑step instructions—including backing up existing .repo files, downloading Alibaba Cloud mirrors, adjusting version numbers, refreshing the cache, verifying updates, troubleshooting common errors, and advanced tips such as adding EPEL—so you can achieve faster, more reliable package management.
YUM (Yellowdog Updater Modified) is the package manager for CentOS. Its default repository servers are located abroad, which often leads to slow download speeds, connection timeouts, and outdated package versions for users in China.
Download speed is very slow (tens of KB/s).
Connection timeout errors (e.g., "Could not resolve host").
Package versions lag behind.
Recommended domestic mirrors:
Mirror Name
Features
Suitable Scenarios
Alibaba Cloud
Many nodes, fast updates
Production environments (preferred)
NetEase 163
Complete historical versions
Compatibility with legacy projects
Tencent Cloud
Dedicated line optimization, low latency
Games / real‑time applications
Huawei Cloud
Enterprise‑grade security hardening
Finance / government projects
Preparation
Connect to the CentOS 7 server using tools such as Xshell or FinalShell.
Install basic download tools.
yum install -y wget curl vim # three essential tools: download + editFour Steps to Replace YUM Repositories (Alibaba Cloud example)
Step 1: Backup original configuration
cd /etc/yum.repos.d/ # enter config directory
mkdir backup # create backup folder
mv *.repo backup/ # move all .repo files to backupStep 2: Download new repository file
# Download Alibaba Cloud CentOS 7 repo
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repoStep 3: Fix the version number
sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo # force version 7Step 4: Refresh the cache
yum clean all # clear old cache
yum makecache # generate new cacheVerification
yum update -y # test system updateIf you see a message like Complete! 已更新XXX个软件包 , the replacement was successful.
Common Issues
❌ Issue 1: Cannot connect to the mirror
ping mirrors.aliyun.com # test network connectivity
vi /etc/resolv.conf # add DNS, e.g., nameserver 8.8.8.8❌ Issue 2: No valid baseurl
Check the baseurl in the .repo file and ensure the CentOS version is set to 7.
💡 Alternative mirror
wget http://mirrors.163.com/.help/CentOS7-Base-163.repoPrinciple Explanation
YUM workflow: .repo configuration → check repository URL → download metadata → install/update packages.
Why change the version number? After CentOS 8 reached end‑of‑life, mirrors must explicitly specify version 7 to avoid automatic mismatches.
Advanced Tips
Use multiple mirrors simultaneously
# Add EPEL repository (recommended)
yum install -y epel-release
sed -i 's|^#baseurl|baseurl|' /etc/yum.repos.d/epel.repo # uncomment baseurlRestore original configuration
mv backup/*.repo /etc/yum.repos.d/ # move backup files backPrecautions
⚠️ Always back up before modifying production servers.
⚠️ Do not enable multiple base sources at the same time to avoid conflicts.
⚠️ If you encounter GPG key errors, you can temporarily disable verification with gpgcheck=0 .
By switching to domestic mirrors, your CentOS 7 server will enjoy faster download speeds and more stable updates.
IT Xianyu
We share common IT technologies (Java, Web, SQL, etc.) and practical applications of emerging software development techniques. New articles are posted daily. Follow IT Xianyu to stay ahead in tech. The IT Xianyu series is being regularly updated.
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.