Centos8:无法使用yum命令安装

时间:2025-03-25 07:06:47

问题:centos 8 使用yum命令报错信息如下:

Errors during downloading metadata for repository 'AppStream':
  - Status code: 404 for /centos/8/AppStream/x86_64/os/repodata/ (IP: 39.96.118.191)
Error: Failed to download metadata for repo 'AppStream': Cannot download : Cannot download repodata/: All mirrors were tried

方案一(不可行):修改vim 中baseurl的地址,报错信息如下:只修改下载源路径不可行,大家别踩坑哦

Errors during downloading metadata for repository 'BaseOS':
  - Status code: 404 for /centos/8/BaseOS/x86_64/os/repodata/ (IP: 100.100.2.148)
Error: Failed to download metadata for repo 'BaseOS': Cannot download : Cannot download repodata/: All mirrors were tried

方案二(实测有效):执行以下4步即可

  1. 运行下面的命令备份文件
rename '.repo' '.' /etc//*.repo
  1. 运行下面命令,下载最新的repo文件
wget /repo/Centos-vault-8.5. -O /etc//Centos-vault-8.5.
wget /repo/ -O /etc// #如果后期 yum clean all && yum makecache报错下载xml文件404,则不需要执行这一句
  1. 运行以下命令替换repo文件中的链接。
sed -i 's//url_tmp/g'  /etc//Centos-vault-8.5. &&  sed -i 's///g' /etc//Centos-vault-8.5. && sed -i 's/url_tmp//g' /etc//Centos-vault-8.5.
sed -i 's///g' /etc//  #如果后期 yum clean all && yum makecache报错下载xml文件404,则不需要执行这一句
  1. 重新创建缓存
yum clean all && yum makecache