From the shell and without root privileges, how can I determine what Red Hat Enterprise Linux version I'm running?
Ideally, I'd like to get both the major and minor release version, for example RHEL 4.0 or RHEL 5.1, etc.
From the shell and without root privileges, how can I determine what Red Hat Enterprise Linux version I'm running?
Ideally, I'd like to get both the major and minor release version, for example RHEL 4.0 or RHEL 5.1, etc.
You can use the
lsb_release
command on various Linux distributions:This will tell you the Distribution and Version and 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.
For RHEL, you should use:
You can look at the contents of /etc/redhat-release, which will look something like this:
The contents are different for an actual RHEL system. This technique works on all RedHat derivatives, including CentOS, Fedora, and others.
I prefer to use the /etc/issue file.
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).
The most reliable way when
lsb_release
is not installed is:On minimal installs,
lsb_release
is missing.To get this working also with Red Hat clones (credit goes to comments):
Or, as a single command (rather than two "rpm"'s being executed):
Use
sed
/cut
and other text manipulating UNIX tools to get what you want.Assuming it truly is a Red Hat release (not Centos):
Or just run:
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).
I prefer
hostnamectl
:I quite like using the
/etc/os-release
file, which is in the release RPM:This file can be sourced in scripts, like:
If you want to just get the version numbers the following is about as short and simple as I can get it.
Tested on rhel 6.7, rhel 7.2, debian 8.3 and ubuntu 14.04:
For a practical example, say you want to test for the distribution major and minor version and do things based on that:
A late arrival to this, but I had fun trying to figure out the RHEL version on several remote nodes. So, if you have a batch of servers that use the same password (I know, I know...) here is a quick and dirty to check the RedHat version:
Create an expect script
Expect script to check major RedHat version on multiple remote hosts
Run the script for all your nodes
Output