What version of RHEL am I using?
Solution 1
You can use the lsb_release
command on various Linux distributions:
lsb_release -i -r
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:
cat /etc/redhat-release
Solution 2
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.
Solution 3
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).
Solution 4
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.
Solution 5
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).
Kevin Son
TLDR Clojure, Docker, Linux, Security, Teaching. https://www.linkedin.com/learning/instructors/arthur-ulfeldt?u=2125562 contacting me: If you are interested in learning clojure you can call me at 1-219-CLOJURE For general Clojure chatting you can find me in IRC #clojure on freenode (thearthur) email < my first name >@< my last name >.com Interests I'm a Clojure and Linux nut with a long standing interest in virtual machines and fancy networking of all sorts. At work I write Clojure Web apps and such full time for yummly.com as well as writing "cloud" deployment systems (some would call it "devops", though I think that term is worn out by now). At home I play with Clojure, Linux, docker, Amateur Radio, and Cryptography quite a bit. I have been a functional programming enthusiast for many years and get quite a lot of personal satisfaction every time i use anything map-reduce related. I am interested in network security related projects and people that are trying to steer the world away from "the corporate castle" metaphor. If you have or are thinking about such a project I would love to hear from you. note for recruiters: I would like to politely decline any positions you might have with "devops" or "language-name engineer" in the title. PS: KE6DRD
Updated on September 17, 2022Comments
-
Kevin Son over 1 year
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.
-
Decebal over 14 yearscommand not found on my CentOS 5.4 box :(
-
Zypher over 14 years@gbjbaanb: That's strange I tested it on a fresh 5.4 minimal install and it worked just fine...
-
Tom about 13 years
lsb_release -i -r
-bash: lsb_release: command not found. However,cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.6 (Tikanga) -
Dan Pritts almost 11 yearsThis 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. -
sborsky over 10 yearsJust for the record: Does not work on RHEL 6.5 minimal install. Command lsb_release is nowhere to be found.
-
lzap over 10 yearsYeah thanks, one note: does not work with RHEL Worstation.
-
fsoppelsa over 10 yearsThis is the most appropriate answer to the question.
-
Jens Timmerman over 10 yearslsb_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...
-
Stefan Lasiewski over 9 years
/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. -
mika over 9 yearsOh ! And now that time has passed, what would be RHEL6 ? RHEL7 ? Hum... Here are the answers: access.redhat.com/articles/3078#RHEL7
-
David Tonhofer over 9 yearsThis is not reliable. Apparently
/etc/issue
is meant to be parsed by agetty, which replaces the escape sequences with proper information. If you justcat
it, the result may be underwhelming. On Fedora, one getsFedora release 20 (Heisenbug) Kernel \r on an \m (\l)
, which tells you something but on RHEL7, one just gets\S Kernel \r on an \m
. -
Dan Pritts about 9 yearsOne note - this runs a lot slower than parsing /etc/foo-release.
-
warren about 9 yearsor
rpm -qa | grep release
is even easier -
chicks almost 9 years
lsb_release
is the first thing to try, but since that might not be installed looking at files is a good Plan B. -
bye almost 7 years@chicks Given that the question asks for a test for Redhat systems, and lsb_release is not installed by default on redhat systems and /etc/redhat-release is, then lsb_release is obviously not the first thing to try!
-
bye almost 7 years"For RHEL, you should use..." And after all, this question is specifically about RHEL...
-
Dan Pritts over 6 yearsInteresting, useful. Unfortunately, not present on RHEL6 so of limited value at the moment.
-
Neil Mayhew over 6 yearsIf you're going to do remote stuff on a lot of machines, I strongly recommend using Ansible rather than hand-rolled bash scripts.
-
Neil Mayhew over 6 yearsI also recommend not enabling root login over ssh
-
Dennis Nolte over 5 years@bye It is the first thing to try (at least in my opinion) , you always try the things which should be common on all distributions first, then only you switch to distribution-specific solutions.
-
user2751502 over 5 yearsNote that
/etc/issue
may be replaced by the local admin and hence is not a reliable source of information.