Determining the version of CentOS on a system

Learning that lasts. Online courses from $14.99

If you are logged into a CentOS Linux system, there are a few ways you can determine the version of CentOS running on the system from a command-line interface (CLI), i.e., a shell prompt.

In the /etc directory, there should be a /etc/centos-release file containing information on the version of CentOS.

CentOS Linux Administration
CentOS Linux Administration
1x1

$ ls -l /etc/*elease
-rw-r--r--  1 root root  27 Mar 28  2017 /etc/centos-release
-rw-r--r--. 1 root root 152 Nov 25  2013 /etc/lsb-release
lrwxrwxrwx  1 root root  14 Apr 20  2017 /etc/redhat-release -> centos-release
lrwxrwxrwx  1 root root  14 Apr 20  2017 /etc/system-release -> centos-release
$ cat /etc/*elease
CentOS release 6.9 (Final)
LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphi
cs-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
CentOS release 6.9 (Final)
CentOS release 6.9 (Final)
$

To just see the version number, you can use one of the grep commands below.

$ grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release
6.9
$ grep -oE '[0-9]+\.[0-9]+' /etc/centos-release
6.9
$

If CentOS 7 is installed, you can also check the contents of /etc/os-release.

$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

$

For version 7 and earlier versions, You can also use a RPM Package Manager (RPM) command, rpm --eval '%{centos_ver}' or rpm --eval '%{centos}' to see just the major version number or rpm --query centos-release to see the major and minor version information.

$ rpm --eval '%{centos_ver}'
6
$ rpm --eval '%{centos}'
6
$ rpm --query centos-release
centos-release-6-9.el6.12.3.x86_64
$

If the lsb_release utility is installed, you can also use it to determine the version number. The utility is part of the redhat-lsb-core package, which you can install with yum install redhat-lsb-core.

$ lsb_release -d
Description:	CentOS release 6.9 (Final)
$ lsb_release -r
Release:	6.9
$

If the hostnamectl utility, which is provided by the systemd package, is installed, you can also use it to see the version number of CentOS and whether the system has a 32-bit or 64-bit architecture.

$ hostnamectl | grep "Operating \| Architecture"
  Operating System: CentOS Linux 7 (Core)
      Architecture: x86
$