Get “yum” on old CentOS working again

If you have some older CentOS VMs for testing or cross-compiling, you may run into the problem that you can’t install or update the system via “yum” any more:

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

So, what’s the problem here?

CentOS have moved all releases that are EOL (=end of life) to a special domain with a slightly different directory layout. For example:


As you can see, the point versioning now is present in the path. This is no big deal as the won’t be any further releases for the 5.x-branch, so we’re quite safe in putting the value right into the url.

The outdatet URLs may occur several times in the *.repo-file that are located at /etc/yum.repos.d/, so let’s use a handy one-liner to do the work for us:

find /etc/yum.repos.d/*.repo | xargs -i sed -i 's/mirror\.centos\.org\/centos/;s/$releasever/5.11/g;s/mirrorlist/#mirrorlist/g;s/#baseurl/baseurl/g' {}

This also removes the comment-hash from the “baseurl”-lines and adds hashed to the “mirrorlist”-entries. They will not work on “vault” anyway.

If you have any other release-version, just change the string “5.11” as needed.

Now try to invoke “yum”. It should work now again.

Leave a Comment

Your email address will not be published. Required fields are marked *