- 用戶中心
- Centos如何更换系统源
八戒云帮助
Centos如何更换系统源
2026-09-16 05:59
CentOS 系统更换源主要分联网换国内源(适合正常联网场景,提升下载速度)和离线配本地源(适合无网络场景)两种情况,且 CentOS 6/7/8 等版本部分源已归档,操作时需注意版本适配,以下是详细教程:前提准备
- 登录 CentOS 系统,建议用 root 用户操作,非 root 用户需在命令前加
sudo获取权限。- 备份原有 Yum 源配置文件,避免出错后无法恢复,执行命令:
bash运行cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bakBash情况一:联网环境更换国内源
国内常用阿里云、清华大学等镜像源,适配主流 CentOS 7/8 版本,操作如下:
- 下载对应版本的国内源配置文件
不同版本的源地址不同,可根据自身系统版本选择,通过cat /etc/centos-release命令可查看系统版本,具体命令如下:
系统版本 阿里云源命令 清华大学源命令 CentOS 7 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repowget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/repo/Centos-7.repoCentOS 8 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repowget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/repo/Centos-8.repo若系统没有 wget 工具,可先执行 yum install -y wget安装。- 生成并更新缓存
执行以下命令清除旧缓存,再生成新源的缓存,让配置生效:bash运行yum clean all # 清除原有缓存 yum makecache # 生成本地缓存Bash- 验证源是否生效
可执行yum repolist查看当前可用的软件源仓库,也可尝试安装软件测试,比如: