Linux

How to Fix Error Failed to Download Metadata for Repository on CentOS 8

Error: Failed to download metadata for repo ‘appstream’: Cannot prepare internal mirrorlist

The CentOS 8 distribution has stopped receiving updates since December 31, 2021. This means that servers using CentOS 8 are no longer supported by the Official CentOS project.

A common error that CentOS administrators have encountered is the one described below:

Bash
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist

To resolve this error you need to change the mirrors pointing them to this new address: vault.centos.org.

To do this follow these steps:

Step 1 – Enter the “/etc/yum.repos.d/” directory

Bash
cd /etc/yum.repos.d/

Step 2 – Use “Sed” which is a very common command in Linux to replace string

Bash
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*

Then this other command:

Bash
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

Step 3 – Clear cache to search for packages

You can optionally use these commands to clear cached data and check for available packages for upgrade.

Bash
yum clean all
yum check-update

Remembering that in Centos 8 both yum and dnf can be used for package management.

I hope I have contributed!

Leave a Reply

Your email address will not be published. Required fields are marked *