Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist - Centos 8

Linux Habibur Rhoman Joy

On Centos 8, I have run "sudo yum update" but getting this error - 

Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

Here I have given different solution for different situation.

Solution 1:

This error we are getting cause CentOS 8 became EOL at the end of 2021. Better if you migrate to CentOS Stream 8, CentOS 9 or Rocky Linux.

To solve current os you can run these commands -

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

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

If you run these commands then dnf will work, but you will not get any updates.

If you want you can also upgrade to centos 8 stream:

 sudo dnf install centos-release-stream -y
 sudo dnf swap centos-{linux,stream}-repos -y
 sudo dnf distro-sync -y

Solution 2:

If you are using docker, you may face same type of problem. Hope this commands will help you -

FROM centos:8

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

#docker
RUN yum upgrade -y

#other commands

Thank you for reading the article. If you face any problem, don't hesitate to comment below.