How to Check RHEL Version: hostnamectl vs /etc/os-release for Red Hat Linux

Use hostnamectl for a quick human-friendly check, and use /etc/os-release when you need clean data for scripts. Both can show the Red Hat Enterprise Linux version. They just serve different moods. One is the friendly front desk. The other is the filing cabinet with labels that scripts love.

TLDR: Run hostnamectl when you want to quickly see the RHEL version on the screen. Run cat /etc/os-release when you need reliable values in automation, reports, or Ansible tasks. Example: a sysadmin checking 120 servers may use /etc/os-release because parsing it can cut manual checking time by over 80%. If you are just fixing one server at 2 a.m., hostnamectl is probably enough.

Why check the RHEL version at all?

Because Linux likes details. Tiny details. Annoying details.

A package may work on RHEL 9 but fail on RHEL 8. A security fix may apply only to RHEL 7.9. A vendor may ask for the exact version before they even read your ticket. It drives me crazy that “it is Red Hat” is often not enough.

You may need the version for:

  • Installing software with the right repository.
  • Checking support status before a patch window.
  • Meeting audit rules without guessing.
  • Writing scripts that behave differently by release.
  • Opening vendor cases with exact system facts.

The good news is that RHEL gives you more than one way to ask, “Who are you?” The two best everyday choices are hostnamectl and /etc/os-release.

Method 1: Check RHEL version with hostnamectl

The hostnamectl command is part of systemd. It shows system identity details. That includes the hostname, machine ID, kernel, architecture, and operating system.

Run this:

hostnamectl

You may see output like this:

 Static hostname: rhelbox01
       Icon name: computer-vm
         Chassis: vm
      Machine ID: 8f3d72b8c4ab4c91a90a8f1234567890
         Boot ID: 2a9f57b6d1d244a3ba111234567890ab
  Virtualization: kvm
Operating System: Red Hat Enterprise Linux 9.3 (Plow)
     CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos
          Kernel: Linux 5.14.0-362.8.1.el9_3.x86_64
    Architecture: x86-64

The key line is this one:

Operating System: Red Hat Enterprise Linux 9.3 (Plow)

That tells you the major version, minor version, and release nickname. Nice and readable. No fuss.

Why hostnamectl is nice

  • It is easy to remember.
  • It gives a neat summary.
  • It shows the kernel too.
  • It works well during manual checks.
  • It looks good in screenshots for tickets.

If you are logged into one server and need an answer fast, this is your friend.

Where hostnamectl can be annoying

hostnamectl is not always the best for scripts. The output is made for humans. That means spacing and labels matter. Parsing it can feel like scraping soup off a plate.

For example, this works:

hostnamectl | grep "Operating System"

But it is not as clean as reading a variable from a file. Also, in stripped-down containers, hostnamectl may fail because systemd is not running. Expect to waste a few extra seconds wondering why a command that worked yesterday is suddenly being dramatic.

Method 2: Check RHEL version with /etc/os-release

The /etc/os-release file is a simple text file. It stores operating system identification data as key-value pairs. That sounds dull. It is also very useful.

Run this:

cat /etc/os-release

You may see this:

NAME="Red Hat Enterprise Linux"
VERSION="9.3 (Plow)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="9.3"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Red Hat Enterprise Linux 9.3 (Plow)"
ANSI_COLOR="0;31"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:redhat:enterprise_linux:9::baseos"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9"

The most useful lines are:

  • PRETTY_NAME: nice full name.
  • VERSION_ID: clean version number.
  • ID: operating system ID, such as rhel.
  • PLATFORM_ID: platform family, such as platform:el9.

For a quick version only, run:

grep VERSION_ID /etc/os-release

Result:

VERSION_ID="9.3"

Even better, load the file and print the value:

. /etc/os-release
echo $VERSION_ID

Result:

9.3

That is clean. That is script-friendly. That is the sort of thing automation tools enjoy.

Image not found in postmeta

hostnamectl vs /etc/os-release: which should you use?

Here is the simple rule:

  • Use hostnamectl when a human is reading the result.
  • Use /etc/os-release when a script is reading the result.

That covers most cases.

Need Best choice Why
Quick manual check hostnamectl Easy to read.
Automation /etc/os-release Clean variables.
Container checks /etc/os-release Does not need systemd.
Support ticket screenshot hostnamectl Shows helpful system info.
Version comparison /etc/os-release VERSION_ID is easy to parse.

A tiny script example

Say you want to run one command on RHEL 8 and another on RHEL 9. Use /etc/os-release.

. /etc/os-release

if [ "$VERSION_ID" = "9.3" ]; then
  echo "This is RHEL 9.3"
else
  echo "This is something else: $PRETTY_NAME"
fi

This is much cleaner than chopping text from hostnamectl. Your future self will thank you. Maybe not loudly. But still.

What about /etc/redhat-release?

You may also see this classic command:

cat /etc/redhat-release

Example output:

Red Hat Enterprise Linux release 9.3 (Plow)

This file is handy. It has existed for a long time. Many admins still use it from muscle memory.

But for modern scripts, /etc/os-release is usually better. It has structured fields. You can read VERSION_ID without text tricks. Less guessing. Fewer weird bugs.

Can both commands disagree?

Usually, no. They should report the same operating system version. Both pull from system identity data supplied by the OS.

Still, odd systems exist. Containers can be strange. Custom images can be stranger. Someone may edit files by hand. Yes, people do that. No, it is not always a good idea.

If the two results disagree, check these:

  • Are you inside a container?
  • Was the system upgraded recently?
  • Is /etc/os-release a custom file?
  • Is systemd running normally?
  • Does rpm -q redhat-release show the expected package?

This command can help:

rpm -q redhat-release

Example:

redhat-release-9.3-0.9.el9.x86_64

That checks the installed release package. It is useful when the system feels suspicious.

Image not found in postmeta

Best practice for admins

Use both, but use each one in the right place.

  • For humans: hostnamectl
  • For scripts: /etc/os-release
  • For old habits: /etc/redhat-release
  • For package proof: rpm -q redhat-release

If you manage many servers, standardize on /etc/os-release in automation. It saves time. It reduces parsing errors. It also works better across different Linux distributions.

If you are training a junior admin, teach hostnamectl first. It gives a friendly snapshot. Then show /etc/os-release and explain why scripts prefer it.

Quick command cheat sheet

  • hostnamectl — show readable system details.
  • cat /etc/os-release — show structured OS data.
  • grep PRETTY_NAME /etc/os-release — show the friendly OS name.
  • grep VERSION_ID /etc/os-release — show the clean version number.
  • cat /etc/redhat-release — show the classic Red Hat release line.
  • rpm -q redhat-release — verify the installed release package.

The short answer: hostnamectl is best for eyeballs. /etc/os-release is best for code. If you remember that, checking the RHEL version stops being a tiny daily headache.

Thanks for Reading

Enjoyed this post? Share it with your networks.