Failed to Download Metadata for repo 'appstream' in CentOS
Problem
When trying to install packages using yum
or dnf
on CentOS 8, you may encounter the error:
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
This error occurs because CentOS 8 reached End of Life (EOL) on December 31, 2021. The official mirror URLs have been disabled, and the repositories are no longer available through the standard mirror system.
Solution
There are two primary approaches to resolve this issue:
Option 1: Switch to CentOS Stream 8 (Recommended)
The official solution from CentOS is to migrate from CentOS Linux 8 to CentOS Stream 8, which continues to receive updates.
# Install CentOS GPG keys if needed
wget 'http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/centos-gpg-keys-8-3.el8.noarch.rpm'
sudo rpm -i 'centos-gpg-keys-8-3.el8.noarch.rpm'
# Switch to CentOS Stream repositories
sudo dnf --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos
# Synchronize with the new repositories
sudo dnf distro-sync
After completing these steps, yum
and dnf
will work normally with the new CentOS Stream 8 repositories.
TIP
CentOS Stream is a rolling-release distribution that sits between Fedora and RHEL, providing a more stable platform than Fedora while offering newer packages than RHEL.
Option 2: Use Archived Repositories (Temporary Fix)
If you cannot migrate to CentOS Stream, you can temporarily point your system to the archived CentOS 8 repositories:
# Navigate to the repos directory
cd /etc/yum.repos.d/
# Comment out mirrorlist entries
sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
# Enable vault.centos.org as the baseurl
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
# Update your system
sudo yum update -y
WARNING
This solution provides access to archived packages but will not receive security updates or bug fixes. It should only be used as a temporary measure before migrating to a supported distribution.
Dockerfile Solution
If you're encountering this error in a Docker build, modify your Dockerfile:
FROM centos:8
# Fix repository configuration
RUN 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-*
# Install your packages
RUN yum -y install java
# Continue with your build steps
For CentOS Stream 9 Users
If you're using CentOS Stream 9 and experiencing similar issues, check your repository configuration:
# Edit the centos.repo file
sudo vi /etc/yum.repos.d/centos.repo
Ensure that any repositories causing errors have enabled=0
instead of enabled=1
.
Best Practices
- Migrate to a supported distribution - Consider upgrading to CentOS Stream, AlmaLinux, Rocky Linux, or another RHEL-compatible distribution
- Keep systems updated - Regular updates ensure security patches are applied
- Plan for EOL transitions - Monitor end-of-life dates for your distributions and plan migrations accordingly
DANGER
Continuing to use CentOS 8 without security updates exposes your system to vulnerabilities. Migrate to a supported distribution as soon as possible.
Conclusion
The "Failed to download metadata for repo 'appstream'" error occurs because CentOS 8 has reached end-of-life. The recommended solution is to migrate to CentOS Stream 8 using the official migration path. While temporary fixes using archived repositories work, they don't provide ongoing security updates and should only be used as a stopgap measure.