yum切换源、以及损坏后的修复

一、切换yum源为国内源

这里先说明一下,yum源的配置位置在/etc/yum.repos.d/目录下

1. 备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

注意:这一步一定要做,我就是因为忘记做这一步,把yum搞坏了

2. 下载新的CentOS-Base.repo 到/etc/yum.repos.d/
# CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
# 或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

# CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo
# 或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

# CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3. 刷新缓存
yum clean all		# 清空缓存 
yum makecache		# 生成缓存


二、重置yum

我因为没有备份原来的yum源,新的yum源也没有生效,结果yum就挂掉了,我也不知道到底是什么原因,使用yum更新的时候一直报错,网上的方法试了很多都没有;

错误:

Retrieving http://mirror.centos.org/centos-7/7/os/x86_64/Packages/centos-release-7-4.1708.el7.centos.x86_64.rpm
curl: (22) The requested URL returned error: 404 Not Found
error: skipping http://mirror.centos.org/centos-7/7/os/x86_64/Packages/centos-release-7-4.1708.el7.centos.x86_64.rpm - transfer failed

废话不多说,直接说方法:

1. 删除原来的配置

删除/etc/yum.repos.d/文件夹下的所有文件:

rm -rf /etc/yum.repos.d/*
2. 下载官方源
rpm -Uvh --force http://mirror.centos.org/centos-7/7/os/x86_64/Packages/centos-release-7-4.1708.el7.centos.x86_64.rpm

这里后面跟的地址http://mirror.centos.org/centos-7/7/os/x86_64/Packages/centos-release-7-4.1708.el7.centos.x86_64.rpm,是centos 7.4yum源配置,如果想找其他的源的话,可以使用http://mirror.centos.org/centos-7/7/os/这个路径并加以修改,然后一点一点的往下找,知道找到自己的yum源配置位置,使用这个路径就可以更新你这个版本的yum源了

3. 同样要刷新缓存
yum clean all		# 清空缓存 
yum makecache		# 生成缓存
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值