Checking your Red Hat Enterprise Linux version tells you which package repositories and support options are available. Knowing how to check rhel version in linux is essential for system administrators and developers who need to ensure compatibility with software, security updates, and proper configuration. This guide walks you through multiple methods to find your RHEL version quickly and accurately.
Whether you’re managing a single server or a fleet of machines, identifying the exact RHEL release helps you troubleshoot issues and plan upgrades. Let’s dive into the simplest and most reliable commands.
How To Check Rhel Version In Linux
The most straightforward way to check your RHEL version is using the cat /etc/redhat-release command. This file contains the exact release information, including the major and minor version numbers. Open your terminal and type:
cat /etc/redhat-release
You’ll see output like “Red Hat Enterprise Linux Server release 8.4 (Ootpa)” or “Red Hat Enterprise Linux release 9.0 (Plow)”. This method works on all RHEL versions and is the first command most admins use.
Another reliable option is cat /etc/centos-release if you’re on a CentOS system, but for pure RHEL, stick with the redhat-release file. If the file doesn’t exist, try cat /etc/system-release as a fallback.
Using The Hostnamectl Command
The hostnamectl command provides system information including the operating system version. Run:
hostnamectl
Look for the “Operating System” line in the output. It will show something like “Red Hat Enterprise Linux 8.4 (Ootpa)”. This command also displays the kernel version, architecture, and hostname, making it a handy all-in-one tool.
If you prefer a more concise output, use hostnamectl | grep "Operating System" to filter just the version line.
Checking With The Rpm Command
The RPM package manager stores version information for the redhat-release package. Use this command:
rpm -q redhat-release
This returns the exact package version, like “redhat-release-8.4-1.el8.x86_64”. The numbers after the dash indicate the major and minor release. For example, “8.4” means RHEL 8.4.
If you need more details, try rpm -qi redhat-release to see the full package metadata, including the installation date and description.
Using The Lsb_Release Command
If the lsb_release utility is installed, you can check the version with:
lsb_release -a
This displays the Distributor ID, Description, Release number, and Codename. For RHEL, the output might look like:
- Distributor ID: RedHatEnterpriseServer
- Description: Red Hat Enterprise Linux Server release 8.4 (Ootpa)
- Release: 8.4
- Codename: Ootpa
Note that lsb_release may not be installed by default on minimal RHEL installations. You can install it with yum install redhat-lsb-core if needed.
Checking The /Etc/Os-Release File
Modern RHEL systems include a standardized file at /etc/os-release. View it with:
cat /etc/os-release
This file contains variables like VERSION_ID (e.g., “8.4”) and VERSION (e.g., “8.4 (Ootpa)”). It’s used by systemd and other tools for version detection. The format is consistent across many Linux distributions, making it a reliable choice.
You can source this file in scripts to programmatically check the version. For example, source /etc/os-release && echo $VERSION_ID prints just the version number.
Using The Uname Command For Kernel Version
While uname shows the kernel version, not the RHEL version directly, it’s useful for context. Run:
uname -a
Or for just the kernel release:
uname -r
The kernel version often correlates with the RHEL version. For instance, RHEL 8.4 typically uses kernel 4.18.0-305.el8.x86_64. However, this isn’t a definitive method because you can update the kernel independently.
Checking With The Subscription Manager
If your system is registered with Red Hat Subscription Manager, use:
subscription-manager release --show
This displays the current release version set for your system. It’s especially useful for systems that are locked to a specific minor release for stability. The output might be “8.4” or “8.5”.
To see the full subscription status, run subscription-manager status which also shows the version context.
Using The Dnf Or Yum Command
Package managers like dnf or yum can reveal the RHEL version through repository information. Run:
dnf repolist
Or for older systems:
yum repolist
The repository IDs often include the version, like “rhel-8-for-x86_64-baseos-rpms”. This confirms which repositories are enabled and their target release.
You can also check the redhat-release package version with dnf info redhat-release.
Checking The /Etc/Issue File
Some systems display the version in the login banner via /etc/issue. View it with:
cat /etc/issue
This file often contains a short string like “Red Hat Enterprise Linux Server release 8.4 (Ootpa) \n \l”. It’s not always accurate if customized, but it’s a quick check.
Using The Python Platform Module
If you have Python installed, you can check the version programmatically:
python -c "import platform; print(platform.platform())"
Or for more details:
python -c "import platform; print(platform.linux_distribution())"
Note that linux_distribution() is deprecated in Python 3.8+, but still works in many RHEL systems. For Python 3, use distro.id() and distro.version() from the distro module.
Checking With The Ansible Or Puppet Fact
If you use configuration management tools, you can gather facts. For Ansible, run:
ansible localhost -m setup | grep ansible_distribution
This returns the distribution name and version. For Puppet, use facter os to see the operating system details.
Understanding The Output Format
RHEL version numbers follow the format “Major.Minor”, like 8.4 or 9.0. The codename (e.g., “Ootpa” for RHEL 8.4) is for internal reference. Knowing the exact minor version is critical for patch levels and support eligibility.
For example, RHEL 8.4 reached end of life in May 2022, while RHEL 8.6 is still supported. Always verify your version against Red Hat’s support lifecycle.
Common Issues And Troubleshooting
If the /etc/redhat-release file is missing, your system might be a derivative like CentOS or Rocky Linux. In that case, check /etc/centos-release or /etc/rocky-release. For Oracle Linux, look for /etc/oracle-release.
Some containerized environments may not have these files. In Docker containers, use cat /etc/os-release or check the base image version.
If you get “command not found” for hostnamectl, ensure systemd is installed. For minimal installations, install the hostname package.
Automating Version Checks In Scripts
For scripting, use the /etc/os-release file. Here’s a simple bash snippet:
source /etc/os-release
echo "RHEL version: $VERSION_ID"
Or parse /etc/redhat-release with grep:
grep -oP '[0-9]+\.[0-9]+' /etc/redhat-release
This extracts the major.minor number for use in conditional logic.
Why Version Matters For Package Repositories
RHEL repositories are version-specific. Using the wrong repository can break dependencies or install incompatible packages. For example, RHEL 8 repositories won’t work on RHEL 9. Always match your system version to the correct repository URL.
Red Hat provides different repositories for BaseOS, AppStream, and supplementary packages. The version determines which updates you receive.
Checking For Extended Update Support (Eus)
If you’re on a long-term support channel, you might have EUS repositories. Check with:
subscription-manager release --list
This shows available release versions. Your current version is marked with an asterisk.
Comparing Rhel Versions Across Systems
When managing multiple servers, use ssh to run the check remotely:
ssh user@server "cat /etc/redhat-release"
Or use a tool like ansible to gather facts from all hosts at once. This helps ensure consistency across your infrastructure.
Graphical Interface Method
If you’re using the GNOME desktop, go to Settings > About. The “OS Name” and “Version” fields show the RHEL release. This is less common for servers but useful for workstations.
Checking The Kernel Version For Clues
While not a direct method, the kernel version can hint at the RHEL version. For instance, RHEL 8.0 uses kernel 4.18.0-80.el8, while RHEL 8.4 uses 4.18.0-305.el8. Use uname -r and compare with known kernel-to-release mappings.
Red Hat publishes a kernel version table in their documentation. However, this is less reliable if you’ve applied kernel updates.
Using The /Proc/Version File
The /proc/version file contains the kernel version and compiler info. View it with:
cat /proc/version
It includes the kernel version but not the RHEL version directly. Still, it’s a quick check for kernel context.
Checking The Build Date
The /etc/redhat-release file sometimes includes a build date. Use ls -l /etc/redhat-release to see the file timestamp, which can indicate when the system was installed or last updated.
Common Misconceptions
Some users confuse the kernel version with the RHEL version. Remember, the kernel is just one component. The RHEL version refers to the entire distribution release.
Also, don’t rely solely on the /etc/issue file, as it can be customized. Always verify with /etc/redhat-release or /etc/os-release.
Best Practices For Version Management
Document your RHEL versions in an inventory. Use automation to check versions regularly. Subscribe to Red Hat’s security alerts for your specific version.
Keep your system updated within the same minor release to avoid breaking changes. Major version upgrades require careful planning and testing.
Frequently Asked Questions
What Is The Fastest Way To Check RHEL Version?
The fastest method is cat /etc/redhat-release. It returns the version immediately without extra tools.
Can I Check RHEL Version Without Root Access?
Yes, all the commands listed (except subscription-manager) work without root privileges. The /etc/redhat-release file is world-readable.
Why Does My System Show A Different Version Than Expected?
This can happen if you’re using a derivative like CentOS Stream or if the system was upgraded partially. Check the /etc/os-release file for the most accurate information.
How Do I Check The RHEL Version In A Docker Container?
Inside the container, run cat /etc/os-release or cat /etc/redhat-release. If the container uses a minimal base, the version might not be available.
What Is The Difference Between Major And Minor RHEL Versions?
The major version (e.g., 8) indicates a major release with significant changes. The minor version (e.g., 4) indicates a point release with updates and bug fixes. Support lifecycle varies by minor version.
Knowing how to check rhel version in linux is a fundamental skill for any Linux administrator. Use the methods above to quickly identify your system’s release and ensure you’re using the correct repositories and support channels. Regular version checks help maintain system stability and security.