Error: Failed to download metadata for repo 'appstream'
Overview
Error Message
On December 31st, 2021 CentOS 8 went End of Life (EOL). The mirrors change to vault.centos.org which is why your CentOS 8 server can't pull down the appstream repo. And because that repo can't be pulled down it usually stops the whole server from installing or updating anything, even items in other repos that still have new versions available (at least in my experience).
By updating the mirrors to the new domain you'll be able to update the server again, however you should begin switching to another Linux distro ASAP. I suggest RockyLinux if you want to keep using a distro similar to Redhat/CentOS, otherwise you can go the Debian route with something like Ubuntu Server LTS. Checkout DistroWatch for a list of all the popular Linux OS's.
Run the following commands and you should be able to update and install packages again.
The following instructions are the same if you're using dnf or yum. At the end instead of running yum update, you could run dnf update.
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
yum update -y
After running the commands, you should be able to start using yum and dnf again. On one of my servers I had to run dnf/yum update twice before it was running without issue. It could have just been latency on my network, I was getting timeouts on a few of the repos but that went away after the second or third dnf check-update
.
Additional Tips
The follow steps show a more manual way of making the changes instead of using the commands mentioned above.
Go info /etc/yum.repos.d/
and you should see a bunch of .repo files that start with CentOS-Linux.
Use sudo nano filename
or sudo vi filename
to edit the files in terminal or SFTP into the server and copy the files off, edit them locally, and copy them back.
Edit each of those files should have a commented out mirrorlist line and a baseurl line that has a vault.centos.org address.
Here's a few more examples.
Make sure your CentOS-Linux repo files look like these. The mirrorlist.centos.org addresses need to be commented out/removed and the baseurl needs to be set to the vault.centos.org domain.
For easy reference, I attached a zip file containing all the CentOS-Linux repo files so you can copy/paste them if needed. repos.zip