CentOS 7 更换 yum 源(阿里云)+ 扩展 epel 源
- [一、备份现有 yum 源](#一、备份现有 yum 源)
- [二、下载 yum 源(任选其一即可)](#二、下载 yum 源(任选其一即可))
- 三、清理并生成缓存
- [四、安装 EPEL 扩展源(根据需要下载)](#四、安装 EPEL 扩展源(根据需要下载))
- 五、验证是否生效
- 六、一键脚本(阿里云源)
一、备份现有 yum 源
-
备份 yum 源
shellsudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
二、下载 yum 源(任选其一即可)
-
阿里云 CentOS 7 yum 源
shellsudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
-
清华大学 CentOS 7 yum 源
shellsudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/.treeinfo
-
腾讯云CentOS 7 yum 源
shellsudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.cloud.tencent.com/centos/7/os/x86_64/.treeinfo
三、清理并生成缓存
-
清理并生成缓存+更新 yum 包
shell# 清理旧 yum 缓存 sudo yum clean all # 生成新缓存 sudo yum makecache # 更新系统 sudo yum update -y
四、安装 EPEL 扩展源(根据需要下载)
-
安装 EPEL 源
shellsudo yum install epel-release -y
-
替换 EPEL 镜像源(以阿里云为例)
shell# 备份原有 EPEL 源 (如果你之前安装过,请先备份) sudo mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak # 下载阿里云 EPEL 源 sudo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
-
清理并生成缓存
shellsudo yum clean all && sudo yum makecache && sudo yum update -y
五、验证是否生效
-
查看 yum 源,并安装 sl 小火车
shell# 查看当前生效的 YUM 源 yum repolist # 安装小火车 sudo yum install sl -y # 运行小火车 sl
六、一键脚本(阿里云源)
-
一键脚本(阿里云源)
shellsudo bash -c ' cd /etc/yum.repos.d/ && mv CentOS-Base.repo CentOS-Base.repo.bak; curl -o CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo; yum clean all && yum makecache && yum update -y; '
END 配置完成