What Version of CentOS / RedHat am I running?

Torn from the pages of “This is so simple I forget it even after doing it a hundred times.”

UPDATE (because I’m a noob):

As is shown in the comments by Scott Pack and Kenny Rasschaert, my hacktastic way of finding a CentOS machine’s specific release isn’t the best way to do things. It’s best to check the release package:

rpm -qa | grep release

Of course, as Chris S of ServerFault fame points out below, uname -a is useful as well. It shows the build number of your OS, which might not be quite as easy to read as searching your rpms. An example from my laptop:

uname -a
Linux Fedora1530 #1 SMP Wed Nov 23 13:39:51 UTC 2011 i686 i686 i386 GNU/Linux

One thing to note from Scott of the Pack clan (Information Security Expert of Renowned): “one of the first things I do during an investigation is try to figure out what distro I’m looking at. I usually check out /etc/issue/etc/*release*, the package name, and uname. Mostly just to figure out if they all agree.” Thanks Scott!

My original, ignoble method of finding my CentOS version was this:

cat /etc/redhat-release

However, some will contend that this method is not foolproof and that some RedHat based distributions change the release file’s name. A more robust method is as follows:

cat /etc/*release*


  1. Scott Pack

    March 19, 2012 at 1:09 pm

    Checking /etc/issue and /etc/*release* is usually a good quick and dirty method, but sometimes I see those gone for one reason or another. You can also do a “rpm -qa | grep release”.


    • Wesley David

      March 19, 2012 at 1:35 pm

      Updated! Yes, that’s much more elegant.


  2. Kenny Rasschaert

    March 19, 2012 at 1:12 pm

    The senior RHEL admin where I work disproves of this method and doesn’t like me using it in scripts. He claims you can’t rely on the contents of that file, or even on that file being there.

    Here’s how he does it:

    On every RHEL-based box there is a release package (for the default software repository?). You can find it using:
    rpm -qa | grep release
    The version number in that package name is the version number of your system.


    • Wesley David

      March 19, 2012 at 1:35 pm

      I knew it was rather hacky, so it’s nice to see how an official RH engineer likes to do things.


  3. Chris S

    March 19, 2012 at 1:18 pm

    Does “uname” not exist on RHEL and CentOS? It seems to work on just about ever *nix I’ve ever tried and seems much simpler than memorizing random files the Linux Distros like to scatter all over the file system.


    • Gaveen

      March 19, 2012 at 1:25 pm

      uname is there, of course. It’s part of coreutils. It’s just uname isn’t going to tell you which distro it is. Try the man page to find any reference towards distro.


    • Wesley David

      March 19, 2012 at 1:37 pm

      Yes, I totally overlooked that. Post updated!


      • Gaveen

        March 19, 2012 at 1:52 pm

        Ah, my point was ‘uname’ isn’t made to give you ditro names (not yet). For example this is what ‘uname -a’ returns in my computer:
        Linux chaos 3.2.10-3.fc16.x86_64 #1 SMP Thu Mar 15 19:39:46 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

        There only pointer there to which distro I’m running is the “fc16” string in the kernel version, which is reading into a convention. There’s no relaible way to find my distro from this output.


  4. Gaveen

    March 19, 2012 at 1:21 pm

    cat /etc/*release* works for most of the systems but it’s not returnable because there could be multiple files such as readhat-release, lsb-release, etc. Then again things like Debian deviates from this convention. IIRC, it’s /etc/debian_version. On Fedora 16 there’s no /etc/lsb-release file but a lsb-release.d dir. ‘lsb_release -d’ or ‘lsb_release -ir’ will be useful in this case. But this too works only if the distro follows certain LSB specs, therefore it’s not generic.

    /etc/issue is the closest we have for a cross-distro standard. But it’s not there for that purpose and isn’t always reliable. I hope there will be a convention or a standard.


  5. Zoredache

    March 19, 2012 at 1:31 pm

    I tend to prefer `lsb_release -a`, though it does need to be installed. It is required by puppet at least on Debian/Ubuntu.

    Also see http://serverfault.com/questions/119144/how-to-find-out-which-linux-distribution-im-logged-on-to


    • Scott Pack

      March 19, 2012 at 1:39 pm

      The LSB packages do provide some nice info, and I had toyed with using them since the OS version facts for EL is a little more useful. Unfortunately, on a slim, but not minimal, RHEL 6 system it pulled in 55 dependencies, including cups, mesa-dri-drivers, and qt. Not exactly ideal for a headless server.


  6. Ade

    March 20, 2012 at 2:23 am

    This is why Facter exists (it’s normally a dependency for Puppet): http://projects.puppetlabs.com/projects/facter


  7. […] up on Wesley’s post “What Version of CentOS / RedHat am I running?” and also to answer a twitter question from Barry Morrison – here’s how you […]


Leave a Reply

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

Follow TheNubbyAdmin!

follow us in feedly

Raw RSS Feed:

Contact Me!

Want to hire me as a consultant? Have a job you think I might be interested in? Drop me a line:

Contact Me!

Subscribe via Email

Your email address is handled by Google FeedBurner and never spammed!

The Nubby Archives

Circle Me on Google+!

Photos from Flickr

Me on StackExchange

The IT Crowd Strava Group