Fix dnf/yum repo failing after CentOS 8 EOL

Fix dnf/yum repo failing after CentOS 8 EOL

Centos 8 went End of Life on 31/12/2021 and the existing repositories were shutdown. This means that you are no longer able to download anything from the repos and will get errors such as:

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

However there is a solution. The CentOS 8 repo has been frozen and migrated to https://vault.centos.org. While it is recommended to move to RHEL, AlmaLinux or Rocky Linux you can still get access to the frozen repo if that is not yet possible.

To do this you will need to change the urls in yum.repos.d. Using the below sed commands you can do this quickly.

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-*

Once done run dnf update and you will be able to install packages again.