How to Check Your CentOS Version Safely (Step-by-Step Guide)

How to Check Your CentOS Version Safely (Step-by-Step Guide)

You’re about to install a package or follow a tutorial, and it says: “Tested on CentOS 7/8 only.” Now you’re staring at an SSH terminal wondering, “Okay… so what CentOS version am I actually on?”

Been there. Knowing your exact CentOS version is important so you:
– Don’t install stuff that only works on another major version
– Use the right repository
– Know if security patches and bug fixes are still available

Let’s walk through several simple ways to check your CentOS version (and kernel) from the command line.


Why Your CentOS Version Actually Matters

If you manage a server, even a small VPS, your CentOS version is not just trivia.

You need it when you:
– Install software that only supports specific CentOS releases
– Follow tutorials that say “for CentOS 7” or “for CentOS 8”
– Configure the correct repo (EPEL, third-party vendors, etc.)
– Check if certain security updates are available for your OS

So before running random copy–paste commands from a blog, first confirm what you’re running. It will save you headaches later.


Step 1 – Check the Linux Kernel Version (uname)

First, let’s see what kernel your system is using. This doesn’t tell you the CentOS version directly, but it’s still useful info.

Run this:

uname -r

That prints just the kernel release, for example:

3.10.0-957.21.3.el7.x86_64

If you want more detail about the system and kernel, use:

uname -a

You’ll see something like:

Linux server1 3.10.0-957.21.3.el7.x86_64 #1 SMP ... x86_64 x86_64 x86_64 GNU/Linux

Why this matters: some apps or drivers care about kernel version, not just OS version. It’s also a quick sanity check that you’re on the kernel you expect.


Step 2 – Check CentOS Version Using rpm

CentOS uses RPM packages, so you can ask rpm what release package is installed.

Try this command:

rpm -q centos-release

That should return something like:

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

From there, you can read that the system is CentOS 7.

If for some reason that package name doesn’t work, there are alternative *-release packages on some systems, but on CentOS, centos-release is the common one.

Why this is useful: it’s a direct query to the package database, which usually reflects the installed CentOS major and minor version.


Step 3 – Use hostnamectl to See OS Info

On systems using systemd, hostnamectl can show OS details, including CentOS version.

Run:

hostnamectl

You’ll get several lines of output. Look for something like Operating System or a similar line that mentions CentOS.

Example (structure only):

   Static hostname: server1
         Icon name: computer-vm
           Chassis: vm
        Machine ID: ...
           Boot ID: ...
  Operating System: CentOS Linux 7 (Core)
            Kernel: 3.10.0-957.21.3.el7.x86_64
      Architecture: x86-64

Again, you can see both the OS name and kernel in one shot.

Why this is useful: quick overview with one command, especially handy when you’re already using other systemd tools.


Step 4 – Use lsb_release (After Installing redhat-lsb)

Some tools and scripts expect the lsb_release command, which is part of the LSB (Linux Standard Base) tools. On CentOS, that comes from the redhat-lsb package.

4.1 Install the redhat-lsb package

First, install it with your package manager:

yum install redhat-lsb

(Use sudo if needed.)

This package provides the lsb_release command, which gives nice, structured OS info.

4.2 Check the CentOS version with lsb_release

After installation, run:

lsb_release -a

You’ll see multiple fields like Distributor ID, Description, Release, and Codename.

You can also use shorter options if you just need the release number:

lsb_release -r

Why this is useful: some deployment scripts and documentation refer to lsb_release, so it’s convenient to have it installed, especially on servers that run multiple apps.


Step 5 – Read the Distro Release Files

Even without extra packages, CentOS usually drops version info into simple text files. These are fast to check and don’t rely on any package tools.

5.1 Check `/etc/centos-release`

This is the classic place to look.

Run:

cat /etc/centos-release

You’ll get a human-friendly line that clearly states the CentOS version.

Why this is useful: it’s simple, direct, and works even on very minimal systems.

5.2 Check `/etc/system-release`

Another file you can try is:

cat /etc/system-release

This often contains the same or similar information as centos-release and is also a common reference for scripts or third-party tools.

5.3 Check `/etc/os-release`

Many modern Linux distributions, including CentOS, use a standardized file called os-release.

Run:

cat /etc/os-release

You’ll see lines like NAME=, VERSION=, and ID= that describe the OS and version in a structured way.

Why this is useful: lots of automation tools parse this file because its format is consistent across many distros.


Which Method Should You Use When?

You’ve got several options now. Here’s when I usually pick each one:

  • Need a quick, human-readable answer?
  • cat /etc/centos-release or hostnamectl
  • Writing scripts or Ansible roles?
  • Parse /etc/os-release or use lsb_release -a (after installing redhat-lsb)
  • Checking if the system is what you think it is after a major update?
  • Combination of rpm -q centos-release and cat /etc/centos-release
  • Verifying kernel-specific requirements?
  • uname -r

None of these commands will break your system; they’re all read-only. So you can safely run them even on production servers.


Quick Safety and Best Practices

A few small habits that help when working on real servers:

  • Use a non-root user with sudo when possible
  • You don’t need full root access just to check versions.
  • Copy–paste carefully
  • A typo in read-only commands is usually harmless, but it’s good discipline, especially on busy production boxes.
  • Keep notes of your server versions
  • When you discover a server is on a certain CentOS version, write it down in your documentation or password manager notes. Future you will be grateful.
  • Match tutorials with your version
  • If a guide says “CentOS 7” and you’re on another major version, expect differences. Package names, config locations, or repositories may not match.

Recap: Fast Checklist to Know Your CentOS Version

When you SSH into a box and need to know what CentOS you’re dealing with, you can quickly run:

  1. Kernel info:
    bash
    uname -r
  2. OS from release package:
    bash
    rpm -q centos-release
  3. OS info via systemd:
    bash
    hostnamectl
  4. LSB-style output (after installing redhat-lsb):
    bash
    yum install redhat-lsb
    lsb_release -a
  5. Release files:
    bash
    cat /etc/centos-release
    cat /etc/system-release
    cat /etc/os-release

Once you know your CentOS version, you can choose the right repositories, follow the correct how-to guides, and avoid installing software that’s not meant for your system.

If this saved you time, bookmark CrushEdge for more fixes.

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.