Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I determine from the shell with no privileges what the Red Hat Enterprise Linux version is, for example is it RHEL 4 or RHEL 5.1?

share|improve this question

9 Answers 9

up vote 52 down vote accepted

You can use the lsb_release command on recent linux distributions. If you issue:

lsb_release -i -r

it will tell you the Distribution and Version. This is a little bit more accurate than accessing files that may or may not have been modified by the admin or a software package. As well as working across multiple distros.

share|improve this answer
3  
command not found on my CentOS 5.4 box :( –  gbjbaanb Dec 1 '09 at 17:04
    
@gbjbaanb: That's strange I tested it on a fresh 5.4 minimal install and it worked just fine... –  Zypher Dec 1 '09 at 18:25
9  
lsb_release -i -r -bash: lsb_release: command not found. However, cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.6 (Tikanga) –  Tom May 10 '11 at 12:12
2  
Just for the record: Does not work on RHEL 6.5 minimal install. Command lsb_release is nowhere to be found. –  sborsky Feb 6 at 9:18
1  
lsb_release is not a lightweight package, It pulls in CUPS to provide ‘/usr/bin/lp’, which pulls in some pdf translation goop, which pulls in some rendering libraries... –  Jens Timmerman Feb 21 at 8:39

You can look at the contents of /etc/redhat-release, which will look something like this:

$ cat /etc/redhat-release 
CentOS release 5.4 (Final)

The contents are different for an actual RHEL system. This technique works on all RedHat derivatives, including CentOS, Fedora, and others.

share|improve this answer
4  
This is the most appropriate answer to the question. –  fsoppelsa Feb 19 at 17:01

I prefer to use the /etc/issue file.

$ cat /etc/issue

I've seen many situations where /etc/redhat-release has been modified to meet software compatibility requirements (Dell or HP's management agents, for instance).

share|improve this answer
    
/etc/issue also works on other OSes as well, such as Debian & Ubuntu, and works with Linux OSes that don't conform to the Linux Standards Base, and lightweight OSes that don't have the lsb* utilities installed. –  Stefan Lasiewski Oct 29 at 21:29

Assuming it truly is a Red Hat release (not Centos):

rpm -q redhat-release

Or just run:

uname -r

And map the output. 2.6.9 kernels are RHEL4, 2.6.18 kernels are RHEL5. If necessary, you can map the full version to the specific update releases from Red Hat (i.e. 2.6.9-89 is RHEL5 U4).

share|improve this answer
1  
rpm -q redhat-release just returns package redhat-release is not installed for me, and uname -r just tells me the kernel release. –  Mark Booth Aug 20 at 13:31
    
Oh ! And now that time has passed, what would be RHEL6 ? RHEL7 ? Hum... Here are the answers: access.redhat.com/articles/3078#RHEL7 –  mika Nov 12 at 14:53

If you have RHEL, this will work (verified on RHEL 5.5):

/usr/bin/lsb_release --d

This will also work on CentOS.

Edit: This tool is included in the package "redhat-lsb", you need to have this installed: yum info redhat-lsb | grep Repo

Repo : installed

share|improve this answer
    
Just for the record: Does not work on RHEL 6.5 minimal install. Command lsb_release is nowhere to be found. –  sborsky Feb 6 at 9:19
    
Minimal probably doesnt inlcude this package: redhat-lsb-core It contains the lsb_release. –  tore- Feb 26 at 12:37

The most reliable way when lsb_release is not installed is:

# rpm -q --queryformat '%{VERSION}' redhat-release-server
6Server

# rpm -q --queryformat '%{RELEASE}' redhat-release-server
6.4.0.4.el6

On minimal installs, lsb_release is missing.

To get this working also with Red Hat clones (credit goes to comments):

# rpm -q --queryformat '%{VERSION}' $(rpm -qa '(redhat|sl|slf|centos|oraclelinux)-release(|-server|-workstation|-client|-computenode)')

Or, as a single command (rather than two "rpm"'s being executed):

# rpm -qa --queryformat '%{VERSION}\n' '(redhat|sl|slf|centos|oraclelinux)-release(|-server|-workstation|-client|-computenode)'

Use sed/cut and other text manipulating UNIX tools to get what you want.

share|improve this answer
    
This seems to work, more generically: rpm -qa '(oraclelinux|sl|redhat|centos)-release(|-server)' sl is for Scientific Linux; if you know the right name for other RHEL rebuilds maybe comment below. Warning - not extensively tested. –  Dan Pritts Aug 8 '13 at 15:47
1  
Yeah thanks, one note: does not work with RHEL Worstation. –  lzap Feb 6 at 14:15

This answer builds upon each of the answers before it. From my understanding of the question, it is just the version number that is required; not the distributor id, etc. To extract it cleanly:

Using lsb_release:

This is authoritative.

$ lsb_release -rs
6.5

Or equivalently:

$ lsb_release --release --short
6.5

If lsb_release is unavailable, it can be installed:

$ sudo yum -y install redhat-lsb

Using /etc/issue:

$ egrep -o '[0-9.]{1,}' /etc/issue
6.5

Or equivalently:

$ egrep --only-matching '[0-9.]{1,}' /etc/issue
6.5

Note that /etc/redhat-release can alternatively be used instead of /etc/issue. Substituting 0-9 with the posix character class [:digit:] also works.

Using rpm:

Be cautioned that using rpm below does not return the answer as authoritatively as is returned by lsb_release.

Replace centos-release below as relevant.

$ rpm -q --qf '%{VERSION}' centos-release
6.5

Or equivalently:

$ rpm --query --queryformat '%{VERSION}' centos-release
6.5

Or more generally:

$ rpm -qa --qf '%{VERSION}' '(redhat|sl|slf|centos|oraclelinux)-release(|-server|-workstation|-client|-computenode)'
6.5

Note that -a (or --all) is necessary in the particular command above. If it returns duplicate output, appending | head -n 1 should help.

Using python:

Assuming Python 2.6 or newer,

$ python -c 'import platform; print(platform.linux_distribution()[1])'
6.5
share|improve this answer

I think that's the quickest way:

cat /etc/*release*

Example:

[root@centolel ~]# cat /etc/*release*
CentOS release 6.5 (Final)
LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
CentOS release 6.5 (Final)
share|improve this answer

A really stupid way is to look at the GRUB menu which usually includes such information :

/boot/grub/menu.lst

This not the smartest way to do such a thing but will work on any distribution / UNIX that uses GRUB.

share|improve this answer
1  
This absolutely does not contain the RHEL version number as is shown in /etc/redhat-release, e.g. 6.5. –  A-B-B Oct 29 at 16:47

protected by Chris S Nov 13 at 15:37

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.