Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

The Quick Answer

cat /etc/redhat-release

The output is one line with the distribution name, the word release, the version number, and a release name in parentheses. The file exists on Red Hat Enterprise Linux and on the compatible distributions AlmaLinux and Rocky Linux, so the same command answers the question on all three. No sudo is needed.

Each Distribution's Own File

FilePresent on
/etc/redhat-releaseAll three
/etc/almalinux-releaseAlmaLinux
/etc/rocky-releaseRocky Linux
/etc/system-releaseAll three

On AlmaLinux and Rocky Linux, /etc/redhat-release and /etc/system-release are links to the distribution's own file, so they all print the same line. Check with ls -l /etc/*release.

/etc/os-release for Scripts

cat /etc/os-release

This file exists on every current Linux distribution. The lines that matter here:

  • ID: the distribution, such as rhel, almalinux, or rocky.
  • ID_LIKE: related distributions; it names the RHEL family on AlmaLinux and Rocky Linux.
  • VERSION_ID: the release number, such as 9.6.
  • PLATFORM_ID: the major release in the form platform:el9 or platform:el10.
  • PRETTY_NAME: the full name for display.

In a shell script, load the file and use the values:

. /etc/os-release
echo "$ID ${VERSION_ID%%.*}"

The %%.* part cuts everything after the first dot, which leaves the major release.

hostnamectl

hostnamectl

The Operating System line shows the full name and release, and the Kernel line the running kernel. It is a good summary when you also want the virtualization type and host name.

Ask the Package Database

rpm -q almalinux-release
rpm -q rocky-release
rpm -q redhat-release

Only the one that matches your system is installed; the others report that the package is not installed. The package version includes the release number. To print only the major release, ask rpm for the macro the distribution defines:

rpm -E %{rhel}

It prints a single number, such as 9, and is handy in scripts that choose a repository by major release.

Major and Minor Releases

The number before the dot is the major release, such as 8, 9, or 10. Each major release has its own package base and is upgraded to the next only by a migration or a reinstall. The number after the dot is a minor release, such as 9.5 to 9.6. Minor releases arrive through normal updates:

sudo dnf upgrade

After that, /etc/redhat-release shows the new minor release. Software built for a major release is meant to keep working across its minor releases.

Release Version vs Kernel Version

uname -r prints the kernel, not the distribution release. On these systems the kernel name contains el and the major release, such as el9, sometimes followed by a minor number. That is only a hint: the kernel can lag behind or run ahead of the installed release. Read the release from the files above and the kernel with uname; how to check the kernel version covers the kernel side, including the difference between the running kernel and the installed ones.

Which Distribution Is This?

If you do not know whether a server runs AlmaLinux or Rocky Linux, the ID line in /etc/os-release settles it. The two are built to be compatible with RHEL and with each other; the differences are in AlmaLinux vs Rocky Linux. On a Debian or Ubuntu server, none of the RHEL files exist; see how to check your Ubuntu version instead.

Was this answer helpful?
Loading...