CentOS 5 "cannot find a valid baseurl for repo" Error Fix

When trying to update or install packages on older CentOS 5 systems, you may run into the following error.

root@server1 [~]# yum update -y
Loaded plugins: fastestmirror
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/
removing mirrorlist with no valid mirrors: /var/cache/yum/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base

This is commonly caused by attempting to use deprecated repositories. The update repositories were moved to the CentOS vault when the operating reached it's end-of-life.

In order to continue using the operating system packages, you will need to update your repository entries to point to the vault.

Using your favorite text editor, open /etc/yum.repos.d/CentOS-Base.repo

Look for the following:

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

Comment out the mirror list, and uncomment the baseurl. So it should look like the following:

#mirrorlist=
baseurl=

Next, you will need to put in the URL for the vault repository.

for 32-bit systems, use: http://vault.centos.org/5.11/os/i386/

for 64-bit systems, use: http://vault.centos.org/5.11/os/x86_64/

For each repository, you will need to replace /os/ with what repository subdirectory you need. For example on a 64-bit system, for updates, your URL will look like http://vault.centos.org/5.11/updates/x86_64/ and for extras it will look like http://vault.centos.org/5.11/extras/x86_64/ Always check the old url first to make sure you have right path. You can also check http://vault.centos.org to see all available repositories.

Once you have added this, run the following to clean your yum cache:

yum clean all

Then update yum to start using the new repositories:

yum update