15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started
31.10.2024

How to Check the CentOS Version: A Complete Guide (All Methods)

Knowing exactly which version of CentOS is running on your server is a fundamental skill for any system administrator. Whether you're installing compatible software packages, troubleshooting system issues, planning an OS migration, or managing security updates, having accurate version information is critical. Fortunately, CentOS provides multiple reliable commands to retrieve this data β€” and this guide covers every one of them in detail.

Why Checking Your CentOS Version Matters

Before diving into the commands, it's worth understanding *why* version awareness is so important in production environments:

  • Software compatibility: Many packages and dependencies are tied to specific CentOS major or minor versions.
  • Security patching: Knowing your version helps you identify which CVEs apply to your system and which patches are available.
  • End-of-life planning: CentOS 8 reached end-of-life on December 31, 2021. If you're still running it, you need to know β€” and plan a migration.
  • Support and troubleshooting: When opening a support ticket or consulting documentation, version information is always one of the first things requested.

If you're running a VPS Hosting environment or a Dedicated Server, keeping track of your OS version is a non-negotiable part of responsible server management.

Method 1: Using the cat Command to Read /etc/centos-release

This is the fastest and most straightforward method. CentOS stores its version information in a dedicated release file located at /etc/centos-release.

Command:

cat /etc/centos-release

Example output:

CentOS Linux release 8.5.2111 (Core)

This single line gives you the full version string, including the major version (8), the minor version (5), and the build tag (2111). This is the go-to command for a quick, human-readable version check and works on virtually every CentOS installation without any additional packages.

Method 2: Using hostnamectl for System and OS Details

The hostnamectl command is a systemd utility that provides a broader overview of your system, including the operating system name, version, and kernel. It is particularly useful on CentOS 7 and CentOS 8, which are both systemd-based.

Command:

hostnamectl

Example output:

   Static hostname: myserver.example.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: a1b2c3d4e5f6...
           Boot ID: f6e5d4c3b2a1...
    Virtualization: kvm
  Operating System: CentOS Linux 8 (Core)
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-305.el8.x86_64
      Architecture: x86-64

Focus on the Operating System and Kernel lines. This method is especially valuable when you need both the OS version and kernel version in a single command, making it ideal for quick system audits.

Method 3: Querying the RPM Package Database

Since CentOS is an RPM-based distribution, the version information is also embedded in an installed RPM package called centos-release. You can query it directly using the rpm command.

Command:

rpm -q centos-release

Example output:

centos-release-8.5-4.2111.el8.x86_64

This output is particularly precise β€” it reveals the exact release package version, including the architecture (x86_64). This method is useful in scripting scenarios where you need a machine-parseable string or want to verify the integrity of the release package itself.

Method 4: Reading /etc/os-release for Detailed Distribution Info

The /etc/os-release file is a standardized file present on virtually all modern Linux distributions. It provides structured, key-value information about the OS and is commonly used by scripts, configuration management tools (like Ansible or Puppet), and container runtimes.

Command:

cat /etc/os-release

Example output:

NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

This is the most information-rich method and is the preferred approach for automation. The VERSION_ID field, for example, can be easily extracted in shell scripts using tools like grep or awk:

grep VERSION_ID /etc/os-release

Output:

VERSION_ID="8"

Method 5: Using lsb_release (Linux Standard Base)

The lsb_release command is part of the Linux Standard Base specification and provides distribution identification data. On CentOS, it may not be installed by default, but it can be added easily.

Check if it's available:

lsb_release -a

If not installed, add it with:

sudo yum install -y redhat-lsb-core

Example output after installation:

LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 8.5.2111 (Core)
Release:        8.5.2111
Codename:       Core

While this method requires an additional package, the structured output (especially the Release field) is useful for scripts that need to remain compatible across multiple Linux distributions.

Method 6: Checking the Kernel Version with uname

The uname command reports kernel information. While it doesn't directly report the CentOS version, the kernel version string is closely tied to specific CentOS releases and can be used to cross-reference the OS version when the release files are unavailable or corrupted.

Command:

uname -r

Example output:

4.18.0-305.el8.x86_64

The el8 tag in the kernel string confirms this is a CentOS/RHEL 8 system. For a more complete system overview, use:

uname -a

This is particularly helpful in minimal container images or chroot environments where /etc/centos-release may not be present.

Quick Reference: All Commands at a Glance

Here is a consolidated summary of all methods covered in this guide:

CommandWhat It ShowsRequires Extra Package?
cat /etc/centos-releaseFull version stringNo
hostnamectlOS name, version, kernelNo (systemd required)
rpm -q centos-releaseExact RPM release packageNo
cat /etc/os-releaseStructured OS metadataNo
lsb_release -aLSB distribution infoYes (redhat-lsb-core)
uname -rKernel versionNo

Bonus: Extracting the Version Programmatically

If you're writing a shell script or using a configuration management tool, you may want to extract just the version number cleanly. Here are two practical one-liners:

Extract major version only:

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

Using awk on the release file:

awk '{print $4}' /etc/centos-release

These approaches are particularly useful in automated provisioning scripts on VPS Control Panels or when deploying applications across multiple servers.

CentOS Version End-of-Life Considerations

It's important to note the current support status of CentOS versions:

  • CentOS 6: End of life β€” November 30, 2020
  • CentOS 7: End of life β€” June 30, 2024
  • CentOS 8: End of life β€” December 31, 2021
  • CentOS Stream 8/9: Rolling release, actively maintained

If your version check reveals you're running an end-of-life CentOS release, you should prioritize migrating to a supported distribution such as AlmaLinux, Rocky Linux, or CentOS Stream. Running an unsupported OS exposes your server to unpatched vulnerabilities, which is especially dangerous on internet-facing infrastructure.

When migrating or setting up a new server environment, consider pairing your deployment with a proper SSL Certificate and a registered Domain to ensure your services are both secure and professionally accessible from day one.

Conclusion

Checking your CentOS version is a simple but essential task that every system administrator should be comfortable performing. With six different methods available β€” from reading release files to querying the RPM database β€” you have multiple reliable options regardless of the environment or constraints you're working in.

The best method for most users is cat /etc/centos-release for its simplicity, while cat /etc/os-release is the preferred choice for scripting and automation. Use hostnamectl when you need a quick overview of both OS and kernel information in a single command.

Staying informed about your OS version is just the first step in maintaining a healthy, secure, and well-managed server. Whether you're managing a single VPS with cPanel or overseeing a fleet of Dedicated Servers, version awareness is the foundation of every other administrative task you'll perform.

15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started