How to Check the Linux Distribution, Version, Kernel, and Architecture

The best first step for identifying a Linux distribution and its version is to read /etc/os-release. Its PRETTY_NAME field provides a human-readable name, while ID and VERSION_ID provide identifiers that are easier to use in scripts.

Use hostnamectl when you want a convenient summary of the distribution, kernel, and architecture. Use uname -r for the currently running Linux kernel version, not the distribution version. These values describe different parts of the system and should not be treated as interchangeable.

Commands to run first

To check only the distribution name and version, start with:

cat /etc/os-release

To show only the most useful fields:

grep -E '^(PRETTY_NAME|ID|VERSION_ID|ID_LIKE)=' /etc/os-release

Run the following commands when you also need the kernel release and CPU architecture.

cat /etc/os-release
hostnamectl
uname -r
uname -m

What is a Linux distribution?

Strictly speaking, Linux is the operating-system kernel. A Linux distribution combines that kernel with system tools, libraries, a package manager, an installer, and default configuration to form a usable operating system.

Ubuntu, Debian, Fedora, Rocky Linux, openSUSE, and Arch Linux all use the Linux kernel, but their package formats, update policies, and administration commands differ. Check the distribution family and version before applying installation or server-configuration instructions.

Distribution family Common distributions Package format and tools Values to check
Debian family Debian, Ubuntu, Linux Mint DEB, APT ID and ID_LIKE=debian
Red Hat family RHEL, Fedora, Rocky Linux, AlmaLinux RPM, DNF ID and RHEL- or Fedora-related values in ID_LIKE
SUSE family openSUSE, SUSE Linux Enterprise RPM, Zypper ID and ID_LIKE=suse
Arch family Arch Linux, Manjaro pkg.tar.zst, Pacman ID and ID_LIKE=arch
Independent Alpine Linux and others Distribution-specific ID and the distribution's official documentation

ID_LIKE is supporting information that describes a related or upstream family. It may be absent. Use ID as the primary distribution identifier and consult ID_LIKE only when family compatibility matters.

Check the distribution and version in /etc/os-release

/etc/os-release stores operating-system identification data as KEY=value entries. According to the official systemd os-release specification, software should prefer /etc/os-release and fall back to /usr/lib/os-release when the former is unavailable.

Display all identification fields

cat /etc/os-release

The exact fields vary by distribution, but output commonly resembles:

PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian

This example identifies Ubuntu 24.04 in the Debian family. Patch-level text and other details can vary with the distribution and update state.

Understand the main os-release fields

Field Meaning Typical use
PRETTY_NAME Human-readable distribution name and version Display and manual inspection
NAME Operating-system name without the version Descriptive labels
ID Lowercase distribution identifier Distribution branches in scripts
VERSION_ID Distribution version intended for machine comparison Supported-version checks
ID_LIKE Related or upstream distribution families Determining likely package and configuration conventions
VERSION_CODENAME Code name for the distribution release Repository configuration and documentation

A rolling-release distribution may not have a fixed major version and can omit VERSION_ID. An absent optional field does not mean that the file is invalid.

Use hostnamectl for a system summary

On distributions that use systemd, hostnamectl can show the host name, operating system, kernel, and CPU architecture together.

hostnamectl

The most useful fields are:

  • Operating System: distribution name and version
  • Kernel: currently running kernel release
  • Architecture: system architecture
  • Virtualization: detected virtual-machine or container environment

hostnamectl is a convenient summary, but it may be unavailable in minimal installations, some containers, or distributions that do not use systemd. Use /etc/os-release and uname in those environments.

Distinguish the distribution version from the kernel version

The values reported by uname are not distribution releases such as Ubuntu 24.04 or Rocky Linux 10. They describe the currently running kernel and the hardware architecture.

uname -r
uname -m
uname -a
Command Information returned Example use
uname -r Kernel release Checking driver and kernel-module compatibility
uname -m Hardware architecture Selecting x86_64 or aarch64 packages
uname -a Several kernel-related values on one line Providing a compact troubleshooting summary

A system can keep the same distribution release while receiving a newer kernel. Systems on the same distribution version can also run different kernels. After a kernel package update, uname -r can continue to show the older kernel until the system reboots. The GNU Coreutils uname documentation defines each option.

Use alternative methods on older systems

Check with lsb_release

If lsb_release is installed, it can display the distributor, description, release, and code name.

lsb_release -a

The command is not included in every minimal installation. Check for it first with command -v lsb_release. The Linux Standard Base lsb_release specification describes its output fields.

Read distribution-specific release files

On older systems without /etc/os-release, use a distribution-specific file as a fallback.

cat /etc/redhat-release
cat /etc/debian_version
cat /etc/alpine-release

The availability and format of these files differ by distribution. In automation, prefer /etc/os-release and check only the explicit fallback files that your supported distributions use. Avoid blindly combining every file that matches /etc/*release.

Detect a distribution in a shell script

For installation scripts and operations automation, use ID and VERSION_ID instead of parsing the human-readable PRETTY_NAME.

if [ -r /etc/os-release ]; then
    . /etc/os-release
    printf 'distribution=%s\n' "$ID"
    printf 'version=%s\n' "${VERSION_ID:-unknown}"
    printf 'family=%s\n' "${ID_LIKE:-unknown}"
else
    printf 'distribution=unknown\n'
    uname -srm
fi

The ${VERSION_ID:-unknown} expression uses unknown when the value is unset or empty. Because many os-release fields are optional and distributions can add their own fields, scripts must not assume that every value exists.

When selecting package-management commands, compare ID first and use ID_LIKE only as a supporting condition. Even distributions in the same family can use different repository configurations and package names, so family similarity does not guarantee that every command is interchangeable.

Interpret results in containers, WSL, and chroot

Containers

Inside a container, /etc/os-release normally identifies the user-space distribution in the container image, not the host. In contrast, uname -r can display the kernel shared with the host. It can be normal for these commands to appear to describe different distribution families.

Windows Subsystem for Linux

In Windows Subsystem for Linux (WSL), /etc/os-release identifies the installed Ubuntu, Debian, or other distribution. The output of uname -r can include a string that identifies a WSL kernel. Continue to use /etc/os-release for the distribution version.

chroot environments

Inside a chroot, /etc/os-release identifies the distribution in the chroot file system, while uname describes the kernel shared with the running host. Account for this difference during recovery work and cross-distribution build processes.

Frequently asked questions

What is the most reliable command for checking the Linux version?

To identify the distribution and its release, start with cat /etc/os-release. Check the kernel separately with uname -r and the CPU architecture with uname -m.

Is something wrong if hostnamectl is missing or does not run?

Not necessarily. Minimal environments and distributions that do not use systemd may not provide hostnamectl. Use /etc/os-release and uname to retrieve the information separately.

How can I distinguish CentOS, Rocky Linux, and AlmaLinux?

Check ID in /etc/os-release. These distributions share parts of the same administration model, but their support policies and repositories are separate. Do not treat them as the same distribution based only on ID_LIKE.

Are x86_64 and aarch64 Linux distribution versions?

No. They identify hardware architectures. A distribution release can provide separate x86_64 and aarch64 images, so check the architecture when selecting software packages or installation media.

Summary

Use /etc/os-release for the Linux distribution name and version, hostnamectl for a convenient system summary, uname -r for the running kernel, and uname -m for the architecture.

In scripts, use ID, VERSION_ID, and, when necessary, ID_LIKE instead of parsing PRETTY_NAME. In containers, WSL, and chroot environments, remember that the user-space distribution and running kernel can come from different layers.

More in This Category
Linux tr Command: Translate and Delete Characters

Linux tr Command: Translate and Delete Characters

Learn how to translate and Delete Characters with the Linux tr command, including practical examples, key options, and important precautions.

Linux command Command: Run Commands While Bypassing Aliases and Functions

Linux command Command: Run Commands While Bypassing Aliases and Functions

Learn how to use the Linux command command to check command availability and bypass shell aliases or functions, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux cd Command: Change the Current Directory

Linux cd Command: Change the Current Directory

Learn how to use the Linux cd command to move between directories using absolute, relative, home, and previous paths, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux cut Command: Extract Characters and Fields

Linux cut Command: Extract Characters and Fields

Learn how to extract Characters and Fields with the Linux cut command, including practical examples, key options, and important precautions.

Linux man Command: Read Command Manual Pages

Linux man Command: Read Command Manual Pages

Learn how to use the Linux man command to find and read command manuals, sections, options, and related pages, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux apropos Command: Search Commands by Description

Linux apropos Command: Search Commands by Description

Learn how to use the Linux apropos command to find relevant manual pages by searching description keywords, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux fdisk Command: Inspect and Edit Disk Partitions

Linux fdisk Command: Inspect and Edit Disk Partitions

Learn how to inspect and Edit Disk Partitions with the Linux fdisk command, including practical examples, key options, and important precautions.

Linux zypper Command: Manage Packages on openSUSE and SUSE

Linux zypper Command: Manage Packages on openSUSE and SUSE

Learn how to manage Packages on openSUSE and SUSE with the Linux zypper command, including practical examples, key options, and important precautions.

Linux reboot Command: Restart the System Safely

Linux reboot Command: Restart the System Safely

Learn how to restart the System Safely with the Linux reboot command, including practical examples, key options, and important precautions.

Linux timedatectl Command: Check Time Zone and Time Synchronization

Linux timedatectl Command: Check Time Zone and Time Synchronization

Learn how to check Time Zone and Time Synchronization with the Linux timedatectl command, including practical examples, key options, and important precautions.