How to check CentOS version

The purpose of this tutorial 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, so you can use whichever method is more convenient for you.

In this tutorial you will learn:

  • How to view CentOS version via GUI
  • How to view CentOS version via command line
How to check CentOS version
How to check CentOS version
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System CentOS Linux
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to check CentOS version step by step instructions

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.

The CentOS version consists of three release versions as illustrated below:

How to show the CentOS Release version
How to check centos version from commands line and GUI

To check a version of other Linux distributions visit our how to check Linux version guide.

End of Lifetime (EOL) Dates

The following table represents the official “End of Lifetime” dates for the CentOS operating system.

End of Lifetime (EOL) Dates
End of Lifetime (EOL) Dates. Ref: CentOS Product Specifications

What is the command to check CentOS version?

The following table contains most common and recommended ways on how to check CentOS version on your CentOS Linux server or desktop.

Command Description
$ rpm -q centos-linux-release
$ rpm -q centos-release
CentOS version valid for CentOS 6 and higher. Causes to reveal major, minor and asynchronous CentOS version.
$ 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 Linux cat command to output content of the /etc/centos-release to query CentOS version. Works with CentOS 6 and higher.


Alternative commands to check CentOS version

In case the above-provided commands did not help you to obtain the CentOS version number you may try the following alternative commands.

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: linuxconfig 
        Icon name: computer-vm 
          Chassis: vm 
       Machine ID: 15e085b3b0804a88b04a63b0012f544d 
          Boot ID: 581516a48bb04b8c837d98163ffbcfaf 
   Virtualization: oracle 
 Operating System: CentOS Linux 8 
      CPE OS Name: cpe:/o:centos:centos:8 
           Kernel: Linux 4.18.0-305.10.2.el8_4.x86_64 
     Architecture: x86-64

For more answers try to query all release files within the /etc directory:

$ cat /etc/*elease
CentOS Linux release 8.4.2105 
NAME="CentOS Linux" 
VERSION="8" 
ID="centos" 
ID_LIKE="rhel fedora" 
VERSION_ID="8" 
PLATFORM_ID="platform:el8" 
PRETTY_NAME="CentOS Linux 8" 
ANSI_COLOR="0;31" 
CPE_NAME="cpe:/o:centos:centos:8" 
HOME_URL="https://centos.org/" 
BUG_REPORT_URL="https://bugs.centos.org/" 
CENTOS_MANTISBT_PROJECT="CentOS-8" 
CENTOS_MANTISBT_PROJECT_VERSION="8" 
CentOS Linux release 8.4.2105 

The system you are running may have macros defined which can help you in identifying the major release version of your CentOS Linux server. Try the following:

$ rpm --eval '%{centos_ver}'
8

Lastly, your GRUB boot menu may provide some answers. Checking CentOS version from GRUB mane is not the most reliable way, however it may provide you with some clues:

# grep title /boot/loader/entries/* 
/boot/loader/entries/15e085b3b0804a88b04a63b0012f544d-0-rescue.conf:title CentOS (0-rescue-15e085b3b0804a88b04a63b0012f544d) 8 
/boot/loader/entries/15e085b3b0804a88b04a63b0012f544d-4.18.0-305.10.2.el8_4.x86_64.conf:title CentOS (4.18.0-305.10.2.el8_4.x86_64) 8



Using Programming to check CentOS version

In case you wish to program your way to check the CentOS version automatically you have multiple options available. This section will list some basic examples of how to check CentOS version using Bash script and Python programming language.

Bash Scripting

The following bash script can be used to obtain the CentOS version number given that the /etc/centos-release file exists and is populated.

The below script serves as an example, feel free to modify wherever appropriate. For more information about Bash Scripting visit our bash scripting tutorial:

#!/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

Output:

$ ./check-centos-version.sh 
CentOS Version: 8.4.2105 
Major Relase: 8 
Minor Relase: 4 
Asynchronous Relase: 2105

Python programming

The following python script will output the distribution name along with the OS version number. Note make sure that you have the python3-distro package installed on your system before you try to check the CentOS version with python:

#!/usr/bin/python3

import distro
print(distro.linux_distribution())

Alternatively, one can execute python code directly from the shell:

$ python3 -c 'import distro; print(distro.linux_distribution())'

Output:

$ ./check-centos-version.py 
('CentOS Linux', '8', 'n/a')