Sometimes, especially for Windows Administrators, upgrading CentOS (or any other flavor of Linux, for that matter) can feel a bit like a holdup, and you’re the poor fool behind the register at the convenience store.
Sure, it can be as easy as:
$ yum upgrade
And you’re off to the races, upgrading your CentOS to the latest version, easy as pie.
But what if you don’t want to jump all the way to the latest version, or you have something installed (or a piece of hardware) that is not yet compatible with the latest release?
Repository Tricks
It’s time to invoke some repository tricks. The short version is that you need to tell yum to get the right release (version) of the packages to upgrade the OS. It’s pretty simple, on the surface:
$ yum upgrade --releasever=7.3.1611
For Red Hat Enterprise Linux (RHEL), that really is all you need to do, because it will hunt down the right repository and spring into action.
CentOS, however, only hosts the latest version of the OS on their repository mirrors, so you’ll get the following helpful message:
failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
Break into the Vault
Luckily, CentOS does offer all of their versions (seriously, like all of them) on their vault repository. All you need to do to make the above command work is modify the yum configuration file to point that the vault repo instead of the standard mirror.
Comment out the mirrorlist
and then add the baseurl
in each section of the config file. Note that the default baseurl
won’t do the job, so create a new one instead.
/etc/yum.repos.d/CentOS-Base.repo
[base] ... #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os baseurl=http://vault.centos.org/$releasever/os/$basearch/ ... [updates] ... #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates baseurl=http://vault.centos.org/$releasever/updates/$basearch/ ... [extras] ... #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras baseurl=http://vault.centos.org/$releasever/extras/$basearch/ ... [centosplus] ... #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus baseurl=http://vault.centos.org/$releasever/centosplus/$basearch/ ...
And there you have it. Now, run the yum
command again, and you’ll be in business!
By the way, if you want to peek at the vault and check out what versions they have hiding in there (or you simply don’t know what the exact version numbers are and need to look them up, like me), just browse the vault:
Assuming you don’t need to do this all the time, you might want to undo the changes to the CentOS-Base.repo
file, but if you plan to be very gentle with this server and always carefully update it to something other than the latest version, then just leave the config file as is.
– John
Thanks for the article, it was very helpful. One thing that I found is $releasever in the repos did not appear to work. The error at the end of this reply is what I got. It seems that it only took the first digit of the version string. The command I used was: yum -y update –releasever=7.4.1708. To get around the issue I hard code the release version in the repo file.
http://vault.centos.org/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 – Not Found
LikeLike
Thanks, Charles. That’s good to know. If anyone has another workaround for this (or alternate syntax that looks at more than the first character of the version string) please post a reply.
LikeLike
Hello Charles,
i know this is not a recent thread, but may you be more specific?
Might you indicate the exact correction you did on the repo file?
Thanks
LikeLike
Andrew, in case Charles isn’t following this thread anymore, my guess is that he changed this:
baseurl=http://vault.centos.org/$releasever/extras/$basearch/
to something like this:
baseurl=http://vault.centos.org/1.2.3.4/extras/$basearch/
Charles, if you’re still “listening” please feel free to weigh in and confirm or deny my guess! That said, it’s still odd because I’m not sure why the variable wouldn’t work just as well as a hard-coded string of numbers.
LikeLike
Great stuff! Thanks!
LikeLike