n1wd.com — N1 Web Development Hub
Drive Traffic · Boost Value

One-click switch to CentOS 7 source

Category: Scripts · Published on 2025-08-14

When using CentOS 7 in mainland China, the default Yum repositories may cause slow download speeds or even connection timeouts. This tutorial provides a simple shell script to help you switch to popular domestic mirror sources with just one command.

Script Content

#!/bin/bash
set -e

echo "Backing up the original Yum repo configuration..."
mkdir -p /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/

echo "Downloading Alibaba Cloud CentOS 7 repo configuration..."
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

echo "Cleaning up cache and generating new cache..."
yum clean all
yum makecache

echo "Yum repo has been switched to Alibaba Cloud mirror"

How to Use

  1. Save the script above as switch_centos7_repo.sh
  2. Grant execute permission: chmod +x switch_centos7_repo.sh
  3. Run it as root: sudo ./switch_centos7_repo.sh

You can also replace the download link in the script with other sources such as Tsinghua University Mirror, Tencent Cloud Mirror, and more.

👁 Views: 72
👎 Dislike 0