问题描述
在 CentOS8 中使用 yum
命令安装软件包时遇到如下错误报告
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
问题原因
在2022年1月31日,CentOS团队终于从官方镜像中移除CentOS 8的所有包。
CentOS 8已于2021年12月31日寿终正非,但软件包仍在官方镜像上保留了一段时间。现在他们被转移到 https://vault.centos.org
解决方案
方案一:修改为官方临时支持的源
如果你仍然需要运行CentOS 8,你可以在/etc/yum.repos.d中更新一下源。使用 vault.centos.org
代替 mirror.centos.org
。
命令如下:
# sudo sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
# sudo sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
此解决方案不知道能持续多久,不知道 CentOS 官网会对这个软件仓库支持多久。
方案二:修改为阿里云的源
- 备份原来的源配置
cd /etc/yum.repos.d/ && mkdir backup && mv *repo backup/
- 下载阿里云的源配置
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
- 更新源里面的地址
sed -i -e "s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-*
sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*
- 生成缓存
yum clean all && yum makecache
方案三(未验证)
可在 https://mirrors.aliyun.com/repo/ 下查看阿里云提供的版本。例如 Centos-vault-8.5.2111.repo 。
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
运行 yum makecache 生成缓存
yum makecache
方案四(未验证)
找到配置文件打开 /etc/yum.repos.d
修改 baseurl
为阿里云的地址
cd /etc/yum.repos.d
vim CentOS-Base.repo
内容如下:
[BaseOS]
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial