Knowing which version of CentOS you are running is essential for system maintenance, software compatibility, and security updates. Whether you are managing a single server or a fleet of machines, checking the CentOS version is a quick and simple process. In this article, we’ll go through several methods to identify your CentOS version using the command line.

Method 1: Using the /etc/centos-release File

This is one of the most straightforward ways to find the CentOS version.

Command:

cat /etc/centos-release

Example output:

CentOS Linux release 7.9.2009 (Core)

This command will show the major and minor release version along with the codename.

Method 2: Using the /etc/os-release File

This file contains detailed information about the operating system and is available on most modern Linux distributions.

Command:

cat /etc/os-release

Example output:

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
VERSION_ID="7"

This method provides a bit more metadata and is useful for scripts that need to identify OS details programmatically.

Method 3: Using the hostnamectl Command (CentOS 7+)

If you’re using CentOS 7 or newer, hostnamectl is a convenient tool that also displays OS version info.

Command:

hostnamectl

Example output:

Static hostname: server01
Icon name: computer-vm
Chassis: vm
Machine ID: xxxxxxxxxxxxxxxx
Boot ID: xxxxxxxxxxxxxxxx
Operating System: CentOS Linux 8
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-240.el8.x86_64
Architecture: x86-64

Method 4: Using rpm Query

You can also check the version of the release package installed:

Command:

rpm -q centos-release

Example output:

centos-release-7-9.2009.1.el7.centos.x86_64

This method shows the package version and can confirm whether your system is using CentOS Linux or a related derivative.

Check Kernel Version (Related but Not the Same)

If you’re curious about the Linux kernel version, use:

uname -r

This won’t show the CentOS version itself but can be useful in conjunction with the methods above.

Conclusion

Checking your CentOS version is easy and can be done in multiple ways depending on your preference and system setup. Whether you’re performing system updates, installing compatible software, or troubleshooting, knowing your exact version helps you make informed decisions. Always make sure your CentOS version is still supported to receive critical updates and security patches.