1. 确定linux操作系统版本
lsb_release -a
2. 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
3. 替换yum源
CentOS 8
# 阿里云镜像仓库
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
CentOS 7
# 阿里云镜像仓库
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
CentOS 6
# 阿里云镜像仓库
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
4. 清除缓存
yum clean all # 清除系统所有的yum缓存
yum makecache # 生成yum缓存
# 至此yum源已经更新完,👇下面 6 是个扩展
5. 其他yum源地址:
6. 安装epel yum源(扩展)
EPEL (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额外的软件包,适用于RHEL、CentOS和Scientific Linux.
6.1 查看可用的epel源 & 安装 epel
yum list | grep epel-release
yum install -y epel-release
6.2 备份
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
mv /etc/yum.repos.d/epel.repo.rpmnew /etc/yum.repos.d/epel.repo.rpmnew.backup
6.3 配置阿里镜像提供的epel源
epel(RHEL 8)
# 阿里云镜像仓库
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
epel(RHEL 7)
# 阿里云镜像仓库
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
epel(RHEL 6)
# 阿里云镜像仓库
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
epel(RHEL 5)
# 阿里云镜像仓库
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo
6.4 清除缓存
yum clean all # 清除系统所有的yum缓存
yum makecache # 生成yum缓存
6.5 其他epel源地址:
6.6 其他
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak &&
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak &&
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.bak &&
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &&
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo &&
yum clean all && yum makecache