今天老王在一台 CentOS 6 的服务器上用 yum 命令安装软件时遇到了 YumRepo Error 的错误,尝试 yum update 也会抛出同样的错误:YumRepo Error: All mirror URLs are not using ftp, http[s] or file.,本文分享下解决方法。
一、问题描述与原因
在使用 yum install
或者 yum update
时,均会报错如下:
Loaded plugins: fastestmirror Setting up Update Process Determining fastest mirrors YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. Invalid release/repo/arch combination/ removing mirrorlist with no valid mirrors: /var/cache/yum/i386/6/base/mirrorlist.txt Error: Cannot find a valid baseurl for repo: base
出现这个错误的原因是官方自 2020 年 11 月底起不再维护 CentOS 6 了,所以之前的 yum 存储库也不能用了:
二、问题解决方法
解决方法很简单,就是修改 baseurl。
1、进入到 /etc/yum.repos.d
目录下:
cd /etc/yum.repos.d
先备份原来的 CentOS-Base.repo 文件:
cp CentOS-Base.repo CentOS-Base.repo.old
修改 CentOS-Base.repo 文件:
vi CentOS-Base.repo
主要修改 baseurl 的值,包括 [base]、[updates] 和 [extras]:
[base] name=CentOS-$releasever - Base # mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra # baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ baseurl=https://vault.centos.org/6.10/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 # released updates [updates] name=CentOS-$releasever - Updates # mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra # baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ baseurl=https://vault.centos.org/6.10/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 # additional packages that may be useful [extras] name=CentOS-$releasever - Extras # mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra # baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ baseurl=https://vault.centos.org/6.10/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
清理yum
缓存
yum clean all
之后再执行 yum install
或者 yum update
就一切正常了!