How to determine CentOS version?

How do I determine the version of a CentOS server without access to any graphical interface? I’ve tried several commands:

# cat /proc/version
Linux version 2.6.18-128.el5 (mockbuild@hs20-bc1-7.build.redhat.com)
(gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)) …

# cat /etc/issue
Red Hat Enterprise Linux Server release 5.3 (Tikanga)

but which one is correct: 4.1.2-4 from /proc/version or 5.3 from /etc/issue?

Asked By: Philippe Blayo

||

As you can see in /etc/issue, you’re using CentOS 5.3. (It says Red Hat because CentOS is based upon the RH sources, and some software checks /etc/issue to identify the distro in use; thus, they’d fail if this was changed to CentOS).

The 4.1.2-4 in /proc/version refers to the version of the gcc C compiler used to build the kernel.

Answered By: Renan

In cases like CentOS the actual version is usually placed in /etc/*elease.

cat /etc/*elease

granted this file usually holds the version of the entire OS minus the kernel (since you can choose which to load).
This file will have the same information as /etc/issue but with CentOS instead of RedHat

Answered By: h3rrmiller

The most reliable way of finding MAJOR version of CentOS (5 or 6 etc) is:

# rpm -q --queryformat '%{VERSION}' centos-release
6

For RHEL do this:

# rpm -q --queryformat '%{RELEASE}' redhat-release-server | awk -F. '{print $1}'
7

The only portable way of finding out a version without lsb_release or other tools is:

# grep -oE '[0-9]+.[0-9]+' /etc/redhat-release
6.5
Answered By: lzap
# echo "I am running: `cat /etc/redhat-release` (`arch`)"

Outputs the following:

I am running: CentOS release 6.7 (Final) (x86_64)
Answered By: Ivan Novikov

Correct way is lsb_release -d.

Answered By: gena2x

Here is some command I collected through google, may help someone:

https://forum.directadmin.com/showthread.php?t=15878

cat /etc/*release*
cat /etc/centos-release

http://www.liquidweb.com/kb/how-to-check-your-centos-version/

cat /etc/redhat-release

https://linuxconfig.org/how-to-check-centos-version

# the later two may need some package to install
rpm --query centos-release
hostnamectl
lsb_release -d

I created a gist to record this, too.

Answered By: shellbye

It can be found at the location /etc, inside the file os-release. So type in:

cat /etc/os-release
Answered By: Lijo George

You can determine it by just calling the following command:

hostnamectl

Which will return as the following:

Static hostname: mgbcctli01
     Icon name: computer-vm
       Chassis: vm
    Machine ID: de14d80a0900427894dbcf6137e058e7
       Boot ID: 6865f9839c064bc9be32281d0f262cc8
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
   CPE OS Name: cpe:/o:centos:centos:7
        Kernel: Linux 3.10.0-514.2.2.el7.x86_64
  Architecture: x86-64

You can also use rpm to find details about CentOS version:

rpm --query centos-release

Which will return in my case:

centos-release-7-3.1611.el7.centos.x86_64
Answered By: hd84335

Run rpm --eval '%{centos_ver}' to get MAJOR version of centos.

Answered By: tvorog

The most truly reliable (and short) way to get MAJOR version of either CentOS or RHEL is:

rpm -E %{rhel}

Will give you a value of e.g. 6, 7, or 8 (now that RHEL 8 is out).

Answered By: Danila Vershinin
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.