CentOS8使用yum下载元数据失败怎么解决

发布时间:2022-5-30 10:20

今天在使用centos8使用yum install下载元数据的时候遇到的问题,顺便记录一下,CentOS8 yum install 下载元数据失败的解决办法在这里分享给大家。

  • 详细问题:
[constade@localhost yum.repos.d]$ sudo yum update 
CentOS Linux 8 - AppStream0.0B/s | 0B 00:00
Errors during downloading metadata for repository 'appstream':
- Curl error (6): Couldn't resolve host name for http://mirror.cloud.aliyuncs.com/centos-vault/8.5.2111/AppStream/x86_64/os/repodata/repomd.xml [Could not resolve host: mirror.cloud.aliyuncs.com]
错误:为仓库 'appstream' 下载元数据失败 : Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
  • 问题原因:

CentOS8操作系统版本生命周期结束,Linux社区不再维护,如需过渡使用,则需要换源。

  • 解决办法 备份/etc/repos.d/里的所有文件
cd /etc/repos.d/
sudo rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo

下载最新的repo文件,从阿里云下载

sudo wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
sudo wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
  • 替换源链接
sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g'/etc/yum.repos.d/Centos-vault-8.5.2111.repo 
sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g'/etc/yum.repos.d/epel-archive-8.repo
  • 清除并更新缓存
yum clean all && yum makecache
  • 检验成果
sudo yum update