CentOS 8 更换国内镜像源

📅 2026/6/26 5:40:16
CentOS 8 更换国内镜像源
阿里云 / 网易完整操作CentOS 8 官方已于 2021 年底停止维护官方源已归档至 vault.centos.org直接用默认源会超时 404必须切换国内归档源下面整套命令可直接复制执行。一、备份原源文件mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak二、下载阿里云 CentOS 8 归档源1. 下载 base 源curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo没有 curl 用 wgetwget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo2. 替换源内版本地址关键CentOS8 已 EOL把 repo 里$releasever全局替换成8-streamsed -i s/$releasever/8-stream/g /etc/yum.repos.d/CentOS-Base.repo三、配置 EPEL 国内源必备扩展软件源安装 epel-releasednf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm替换阿里云 EPEL 镜像sed -i s|^#baseurlhttps://download.fedoraproject.org/pub|baseurlhttps://mirrors.aliyun.com| /etc/yum.repos.d/epel* sed -i s|^metalink|#metalink| /etc/yum.repos.d/epel*四、清理旧缓存生成新缓存# 清空缓存 dnf clean all # 生成新缓存 dnf makecache # 测试 dnf list五、网易 163 源备选阿里云慢时使用mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak2 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS8-Base-163.repo sed -i s/$releasever/8-stream/g /etc/yum.repos.d/CentOS-Base.repo dnf clean all dnf makecache常见报错解决报错 Cannot find a valid baseurl for repo: base/8/x86_64原因没替换$releasever重新执行sed -i s/$releasever/8-stream/g /etc/yum.repos.d/CentOS-Base.repocurl: command not found改用 wget 下载源文件即可想用 CentOS 8 传统版非 stream sed 替换为数字 8sed -i s/$releasever/8/g /etc/yum.repos.d/CentOS-Base.repo