CentOS 7 更换 yum 源(阿里云)+ 扩展 epel 源

CentOS 7 更换 yum 源(阿里云)+ 扩展 epel 源


一、备份现有 yum 源

  1. 备份 yum 源

    shell 复制代码
    sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

二、下载 yum 源(任选其一即可)

  1. 阿里云 CentOS 7 yum 源

    shell 复制代码
    sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  2. 清华大学 CentOS 7 yum 源

    shell 复制代码
    sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/.treeinfo
  3. 腾讯云CentOS 7 yum 源

    shell 复制代码
    sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.cloud.tencent.com/centos/7/os/x86_64/.treeinfo

三、清理并生成缓存

  1. 清理并生成缓存+更新 yum 包

    shell 复制代码
    # 清理旧 yum 缓存
    sudo yum clean all
    
    # 生成新缓存
    sudo yum makecache
    
    # 更新系统
    sudo yum update -y

四、安装 EPEL 扩展源(根据需要下载)

  1. 安装 EPEL 源

    shell 复制代码
    sudo yum install epel-release -y
  2. 替换 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
  3. 清理并生成缓存

    shell 复制代码
    sudo yum clean all && sudo yum makecache && sudo yum update -y

五、验证是否生效

  1. 查看 yum 源,并安装 sl 小火车

    shell 复制代码
    # 查看当前生效的 YUM 源
    yum repolist
    
    # 安装小火车
    sudo yum install sl -y
    # 运行小火车
    sl

六、一键脚本(阿里云源)

  • 一键脚本(阿里云源)

    shell 复制代码
    sudo 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 配置完成


相关推荐
Kira Skyler1 天前
ELF文件解析 elf.o 文件主要内容.md
linux
逐梦吧!旅行者1 天前
Linux MySQL 5.7用户管理与用户密码的设置问题
linux·mysql
RisunJan1 天前
Linux命令-grpck命令(验证和修复组配置文件(`/etc/group` 和 `/etc/gshadow`)完整性的工具)
linux·运维·服务器
loosed1 天前
Ubuntu mysql8 tar.xz 安装
linux·ubuntu·adb
Xの哲學1 天前
Linux VxLAN深度解析: 从数据平面到内核实现的全面剖析
linux·服务器·算法·架构·边缘计算
添砖java‘’1 天前
Linux信号机制详解:从产生到处理
linux·c++·操作系统·信号处理
MC皮蛋侠客1 天前
Linux C++使用GDB调试动态库崩溃问题完全指南
linux·c++
Wang's Blog1 天前
RabbitMQ: 消息发送、连接管理、消息封装与三种工程方案
linux·ubuntu·rabbitmq
Vect__1 天前
初识操作系统
linux
若风的雨1 天前
pcie bar 地址对齐规则
linux