Skip to content

CentOS 7 Alibaba Cloud YUM Repository Replacement Tutorial: One-Click Configuration, Download Speed Increased 10x ​

CentOS 7 terminal command-line interface, demonstrating the YUM repository configuration acceleration process

Still enduring the turtle-speed downloads from the default CentOS 7 YUM repository? This article will show you how to switch to the Alibaba Cloud domestic mirror, with one-click configuration, increasing download speed by 10x!

On CentOS 7, when using the default foreign YUM repositories, the download speed for software packages is often only tens of KB/s, and downloads even frequently time out and fail. Replacing the repositories with the domestic Alibaba Cloud mirror can Significantly increase software package download speeds, shortened from minute-level waiting to second-level completion.

This article will provide One-click script and Step-by-step operation Two methods to help you quickly complete the configuration.

One-click configuration script ​

This is the fastest way: just copy the entire script and run it directly:

bash
#!/bin/bash
# Change CentOS 7 YUM source to Alibaba Cloud

echo "=== Configure Alibaba Cloud YUM repository ==="

# 1. Back up the original source
mkdir -p /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ 2>/dev/null

# 2. Download the Alibaba Cloud CentOS 7 repository
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

# 3. Download the Alibaba Cloud EPEL repository (extra packages)
curl -o /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo

# 4. Clear the cache and generate a new cache
yum clean all
yum makecache

# 5. Update the system (optional)
yum update -y

echo "✅ Alibaba Cloud YUM repository configuration completed!"

Execution method:

bash
# Save the script as a file and execute it
vim setup-yum.sh
# Paste the above script content, save and exit.

chmod +x setup-yum.sh
./setup-yum.sh

Or directly paste and execute them one by one as root.

Detailed explanation of step-by-step execution ​

If you want to understand the specific function of each step, you can follow the steps below to operate manually.

Step 1: Back up the original YUM repository ​

To avoid being unable to recover after a configuration error, it is recommended to back up the original source file first:

bash
mkdir -p /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/

💡2>/dev/null Indicates that error messages about a missing .repo file are ignored and do not affect execution.

Step 2: Download the Alibaba Cloud CentOS 7 base repository ​

bash
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

This source contains all packages in the official CentOS 7 repository.

Step 3: Download the Alibaba Cloud EPEL repository ​

EPEL (Extra Packages for Enterprise Linux) is an additional package repository maintained by the Fedora community, providing a large number of software packages not available in the official repositories:

bash
curl -o /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo

Step 4: Clean up and generate cache ​

bash
yum clean all
yum makecache

This step will clear the old cache data and regenerate the metadata cache from the Alibaba Cloud mirror.

Step 5: Update the system (optional) ​

If you want to update all system packages to the latest version, you can run:

bash
yum update -y

⚠️Note: Please execute with caution in the production environment yum update -y, it is recommended to verify compatibility in the test environment first.

Verify whether the source is effective ​

After configuration is complete, verify whether the source is working properly with the following command:

View the list of enabled sources ​

bash
yum repolist

Normal output should look something like the following:

repo id          repo name                             status
base/7/x86_64    CentOS-7 - Base - mirrors.aliyun.com  10,000+
epel/x86_64      Extra Packages for Enterprise Linux   13,000+
extras/7/x86_64  CentOS-7 - Extras - mirrors.aliyun.com  500+
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com  3,000+

Test download speed ​

bash
# Test installation of common tools
yum install -y wget vim net-tools

# If you have configured EPEL, you can test installing software from EPEL.
yum install -y htop

If the download speed reaches MB/s level, indicating the configuration was successful! 🎉

Update kernel (optional) ​

After updating the system, it is also recommended to update the kernel for better performance and security:

bash
# View the current kernel version
uname -r

# Update kernel
yum update kernel -y

# Reboot to make the new kernel take effect
reboot

# Check the kernel version again after reboot.
uname -r

Frequently Asked Questions ​

Q1:curl What should I do if the command does not exist? ​

If the system is not installed curl, can be used wget Alternative:

bash
# Use wget to download
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

If wget There isn't either; first install via the original source:

bash
yum install -y wget curl

Q2: Hint Cannot find a valid baseurl for repo: base? ​

This is usually due to network issues or incorrect source file configuration. Solution:

bash
# Check whether DNS is working properly
ping -c 3 mirrors.aliyun.com

# Check whether there are any leftover repo files in the backup directory
ls /etc/yum.repos.d/

# Ensure that there are only .repo files and no other backup files interfering.

Q3: What is the difference between Alibaba Cloud repositories and EPEL repositories? ​

SourceDescription
CentOS-BaseOfficial CentOS packages maintained by the CentOS team
EPELAdditional packages maintained by the Fedora community, including more third-party tools

It is recommended to configure both to complement each other.

Q4: How to restore the default source? ​

bash
# Delete Alibaba Cloud source
rm -f /etc/yum.repos.d/CentOS-Base.repo
rm -f /etc/yum.repos.d/epel-7.repo

# Source of the backup to restore
mv /etc/yum.repos.d/backup/*.repo /etc/yum.repos.d/

# Clear cache
yum clean all
yum makecache

Actual speed comparison test ​

Source typeDownload speed (average)Time taken to install Docker (2GB package)
默认官方源50~200 KB/sApprox. 3~4 hours ⏰
Alibaba Cloud image5~20 MB/sAbout 3~5 minutes ⚡

📊 The above data comes from actual tests on domestic servers, with speed improvements reaching 10~50 倍.

Reference materials ​

Summary ​

Through the configuration in this article, you have successfully switched the CentOS 7 YUM repository to the Alibaba Cloud domestic mirror. Subsequent installation of any software packages will enjoy Lightning-fast download Experience:

  • One-click script, complete configuration in 3 minutes

  • Download speed increased from KB/s to MB/s

  • Comes with the EPEL repository, offering a richer selection of software packages.

  • Production-ready, stable and reliable

Go ahead and try it now!🚀

Last updated on11/07/2026, 02:16 PM
@fishfinal | @fishfinals | [email protected]