上一篇 下一篇 分享链接 返回 返回顶部

Centos如何更换系统源

发布人:玖云-磊 发布时间:2025-11-29 22:03 阅读量:68
CentOS 系统更换源主要分联网换国内源(适合正常联网场景,提升下载速度)和离线配本地源(适合无网络场景)两种情况,且 CentOS 6/7/8 等版本部分源已归档,操作时需注意版本适配,以下是详细教程:

前提准备

  1. 登录 CentOS 系统,建议用 root 用户操作,非 root 用户需在命令前加sudo获取权限。
  2. 备份原有 Yum 源配置文件,避免出错后无法恢复,执行命令:
    bash
     
    运行
     
     
     
     
    cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
    
     
     

情况一:联网环境更换国内源

国内常用阿里云、清华大学等镜像源,适配主流 CentOS 7/8 版本,操作如下:
  1. 下载对应版本的国内源配置文件
     
    不同版本的源地址不同,可根据自身系统版本选择,通过cat /etc/centos-release命令可查看系统版本,具体命令如下:
    系统版本 阿里云源命令 清华大学源命令
    CentOS 7 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/repo/Centos-7.repo
    CentOS 8 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/repo/Centos-8.repo
    若系统没有 wget 工具,可先执行yum install -y wget安装。    
  2. 生成并更新缓存
     
    执行以下命令清除旧缓存,再生成新源的缓存,让配置生效:
    bash
     
    运行
     
     
     
     
    yum clean all  # 清除原有缓存
    yum makecache  # 生成本地缓存
    
     
     
  3. 验证源是否生效
     
    可执行yum repolist查看当前可用的软件源仓库,也可尝试安装软件测试,比如:
目录结构
全文