如何解决CentOS7在使用yum的时候报错File contains no section headers.

网上搜了一大堆方法,有的靠谱有的不行,有的有时候能用,一会儿又不能用了,我这里总结了一下,两个方法,都比较简单粗暴,可以尝试一下。

第一个方案

删除yum.repos.d目录下所有文件rm -f /etc/yum.repos.d/*
然后重新下载阿里的资源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
注意,上面的参数是大写的英文字母O
然后清除缓存 yum clean all

第二个方案

如果上面的办法不行,那么可以试试这个方法,稍微麻烦点,但是大概率管用。
直接修改CenOS-Base.repo文件内容
修改/etc/yum.repos.d/CenOS-Base.repo文件内容如下:

CentOS-Base.repo

The mirror system uses the connecting IP address of the client and the

update status of each mirror to pick mirrors that are updated to and

geographically close to the client. You should use this for CentOS updates

unless you are manually picking other mirrors.

If the mirrorlist= does not work for you, as a fall back you can try the

remarked out baseurl= line instead.

[base]
name=CentOS- r e l e a s e v e r − B a s e m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Base mirrorlist=http://mirrorlist.centos.org/?release= releaseverBasemirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=os&infra=infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / o s / releasever/os/ releasever/os/basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS- r e l e a s e v e r − U p d a t e s m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Updates mirrorlist=http://mirrorlist.centos.org/?release= releaseverUpdatesmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=updates&in…infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / u p d a t e s / releasever/updates/ releasever/updates/basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS- r e l e a s e v e r − E x t r a s m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release= releaseverExtrasmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=extras&inf…infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / e x t r a s / releasever/extras/ releasever/extras/basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS- r e l e a s e v e r − P l u s m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release= releaseverPlusmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=centosplus…infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / c e n t o s p l u s / releasever/centosplus/ releasever/centosplus/basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

如果不能修改,更改文件的权限

代码如下

chmod 777 CenOS-Base.repo

注意进入到文件所处的地方再修改。
保存退出之后,在执行指令

yum clean all
  • 13
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值