Table of Contents
The purpose of this post is to show how to check the CentOS version of your Linux system. It’s possible to do this from either command line or GUI. Knowing your CentOS version will give you some insight into how long your system will continue to be supported.
How to view CentOS version via GUI
There are several ways on how to check what version of CentOS is running on your system. The simplest way to check for the CentOS version number is to execute the cat /etc/centos-release command. Identifying the accurate CentOS version may be required to help you or your support team to troubleshoot your CentOS system.
How to check CentOS version via command line
The following table contains most common and recommended ways on how to check CentOS version on your CentOS Linux server or desktop.
+-----------------------------+---------------------------------------------------------------+
| Option | Description |
+=============================+===============================================================+
| rpm -q centos-linux-release | CentOS version valid for CentOS 6 and higher. |
+-----------------------------+---------------------------------------------------------------+
| rpm -q centos-release | CentOS version valid for CentOS 6 and higher. |
+-----------------------------+---------------------------------------------------------------+
| lsb_release -d | Requires redhat-lsb package to be installed before execution. |
+-----------------------------+---------------------------------------------------------------+
| rpm -E %{rhel} | RPM macro to reveal a major CentOS version |
+-----------------------------+---------------------------------------------------------------+
| rpm –eval %{centos_ver} | RPM macro to display a major version of CentOS |
+-----------------------------+---------------------------------------------------------------+
| cat /etc/centos-release | Works with CentOS 6 and higher. |
+-----------------------------+---------------------------------------------------------------+
| cat /etc/os-release | Works with CentOS 7 and higher. |
+-----------------------------+---------------------------------------------------------------+
# rpm -E %{rhel}
8
# rpm –eval %{centos_ver}
RPM version 4.14.3
Copyright (C) 1998-2002 - Red Hat, Inc.
This program may be freely redistributed under the terms of the GNU GPL
# cat /etc/centos-release
CentOS Stream release 8
# cat /etc/os-release
NAME="CentOS Stream"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Stream 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream"
Alternative commands to check CentOS version
Although available only for CentOS version 7 and above the hostnamectl command might provide you with a significant clue about your OS version number:
# hostnamectl
Static hostname: ct7
Icon name: computer-vm
Chassis: vm
Machine ID: dc2888319a594372b33b1942e30f938a
Boot ID: c394954417e146c4ac8f4b3f5b4186c9
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.76.1.el7.x86_64
Architecture: x86-64
Check CentOS version using a bash script
Create a bash script using the following lines:
#/bin/bash
full=`cat /etc/centos-release | tr -dc '0-9.'`
major=$(cat /etc/centos-release | tr -dc '0-9.'|cut -d \. -f1)
minor=$(cat /etc/centos-release | tr -dc '0-9.'|cut -d \. -f2)
asynchronous=$(cat /etc/centos-release | tr -dc '0-9.'|cut -d \. -f3)
echo CentOS Version: $full
echo Major Relase: $major
echo Minor Relase: $minor
echo Asynchronous Relase: $asynchronous
Execute the script to check the CentOS version.
# vi version_check.sh
# chmod +x version_check.sh
# ./version_check.sh
CentOS Version: 7.9.2009
Major Relase: 7
Minor Relase: 9
Asynchronous Relase: 2009