Linux 更换yum镜像源

报错信息

File contains no section headers.
file: file:///etc/yum.repos.d/CentOS-Base.repo, line: 1
'\r\n'
[root@localhost ~]# sudo yum makecache
已加载插件:fastestmirror, langpacks


File contains no section headers.
file: file:///etc/yum.repos.d/CentOS-Base.repo, line: 1
'\r\n'
[root@localhost ~]# 

解决方法

删除错误的配置文件

执行以下命令删除当前损坏的 repo 文件:

sudo rm -f /etc/yum.repos.d/CentOS-Base.repo

2. 下载正确的 repo 文件
阿里云镜像源

下载阿里云的 CentOS 7 配置文件:

sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

清华大学镜像源

或者选择清华大学的 CentOS 7 配置文件:

sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/repo/Centos-7.repo

3. 检查文件内容

确认文件内容是否正常:

cat /etc/yum.repos.d/CentOS-Base.repo

正确的内容应该类似于以下格式:

[base] name=CentOS-$releasever - Base baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 [updates] name=CentOS-$releasever - Updates baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

4. 清理缓存并重新生成

清理旧缓存并重新生成 yum 缓存:

sudo yum clean all sudo yum makecache

5. 测试更新

尝试运行更新命令:

sudo yum update -y

你可能感兴趣的:(linux,python,运维)