13.2 CentOS / RHEL(yum)

子章节
CentOS 7
# 备份原配置
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

# 替换为清华镜像源
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

# 生成缓存
sudo yum makecache

或直接下载清华源配置:

# CentOS 7
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/CentOS-Vault-7.repo

# CentOS 8(已停止维护,使用 vault 源)
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/CentOS-Vault-8.repo

sudo yum makecache

CentOS Stream 9 / Rocky Linux / AlmaLinux
# 备份原配置
sudo cp /etc/yum.repos.d/rocky.repo /etc/yum.repos.d/rocky.repo.bak

# 替换为清华镜像源
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.tuna.tsinghua.edu.cn/rocky|g' \
-i.bak \
/etc/yum.repos.d/rocky*.repo

sudo dnf makecache