1. 再查看现在主机上的yum源,并将它们删除
[root@localhost ~]# rpm -qa|grep yum | xargs rpm -e --nodeps # --nodeps 不管有没有依赖的包,都将包删除
2. 下载新的yum包
#这里都是拿的是阿里云的yum源,需要先确定是否还存在资源,再进行下载 # PS: 请按顺序下载 wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-150.el7.centos.noarch.rpm wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-40.el7.noarch.rpm wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
3. 按顺序将下载好的yum源安装
rpm -ivh
4. 更新yum源
# 先备份主机上原先存在的yum源,免得出错 mv /etc/yum.repo.d/rhel-Base.repo ./rhel-Base.repo.bak #下载新的yum源到/etc/yum.repo.d/ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # 编辑Centos-7.repo , 将$releasever字样的地方全部替换为7 vi Centos-7.repo #在vi中命令模式下输入 %s/$releasever/7/g
5. 运行yum makecache生成缓存
yum clean all yum makecache yum update yum list