When working with Red Hat Enterprise Linux servers, many administrators first try these common commands:
uname -r
cat /proc/version
While these show kernel information, they don't reveal the actual RHEL distribution version. Here are more effective methods.
The most reliable way is to check Red Hat's release files:
cat /etc/redhat-release
cat /etc/os-release
Example output for RHEL 7:
Red Hat Enterprise Linux Server release 7.9 (Maipo)
The rpm package manager contains distribution information:
rpm -q --whatprovides redhat-release
Sample output:
redhat-release-server-7.9-1.el7.x86_64
For RHEL 7 and newer systems with systemd:
hostnamectl
This will display the operating system version along with other system information.
For scripting purposes, you can use Python:
import platform
dist = platform.linux_distribution()
print(dist)
Different methods serve different purposes:
- Quick terminal checks: /etc/redhat-release
- Scripting: /etc/os-release (standardized format)
- Package management: rpm queries
- Modern systems: hostnamectl
RHEL Version | Release File Content |
---|---|
RHEL 5 | Red Hat Enterprise Linux Server release 5.11 (Tikanga) |
RHEL 6 | Red Hat Enterprise Linux Server release 6.10 (Santiago) |
RHEL 7 | Red Hat Enterprise Linux Server release 7.9 (Maipo) |
RHEL 8 | Red Hat Enterprise Linux release 8.5 (Ootpa) |
When working with Red Hat Enterprise Linux (RHEL), it's crucial to distinguish between the kernel version and the OS distribution version. While commands like uname -r
or checking /proc/version
reveal kernel information, they don't specify your RHEL release version (like RHEL 7, 8, or 9). Here are several reliable methods to determine your RHEL version.
The most straightforward approach is checking the release file:
cat /etc/redhat-release
Example output:
Red Hat Enterprise Linux Server release 8.6 (Ootpa)
For modern RHEL systems (7+):
hostnamectl | grep "Operating System"
Sample output:
Operating System: Red Hat Enterprise Linux 8.6 (Ootpa)
Query the installed release package:
rpm -q redhat-release
Output might look like:
redhat-release-8.6-1.1.el8.x86_64
This provides more detailed information:
lsb_release -a
Example output:
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 8.6 (Ootpa)
Release: 8.6
Codename: Ootpa
This file contains standardized OS identification data:
cat /etc/os-release
Sample output:
NAME="Red Hat Enterprise Linux"
VERSION="8.6 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.6 (Ootpa)"
When writing scripts that need version checking, consider using this approach:
if [ -f /etc/redhat-release ]; then
RHEL_VERSION=$(sed 's/.*release $[0-9]$.*/\1/' /etc/redhat-release)
echo "RHEL version detected: $RHEL_VERSION"
fi
Different RHEL versions have varying:
- Package management tools (yum vs dnf)
- Systemd implementation differences
- Security and feature backports
- Support lifecycles