Knowing the exact version of your Linux operating system is a fundamental skill for any user, developer, or system administrator. Whether you are troubleshooting a driver issue, verifying software compatibility, applying security patches, or simply satisfying curiosity, the ability to quickly identify your distribution name, version number, and kernel release saves valuable time. Unlike proprietary systems where a single "About" window provides everything, Linux offers a variety of tools—both universal and distribution-specific—to retrieve this data from the command line and graphical interfaces The details matter here..
Why Checking Your Linux Version Matters
Before diving into the commands, it helps to understand what you are looking for. That said, The Distribution (Distro) Version: The specific release of the OS package collection (e. "Linux version" can refer to three distinct layers:
- That's why g. 0-14-generic
). **The Kernel Version:** The core interface between hardware and software (e.Which means ,6. 3. The Codename: Many distributions assign codenames to releases (e.2. Which means g. Think about it: , "Jammy Jellyfish" for Ubuntu 22. 5.On top of that, , Ubuntu 22. 04 LTS, Fedora 39, Debian 12 "Bookworm"). Now, g. 04), which are often used in repository configuration files.
Identifying the correct layer ensures you download compatible .deb or .rpm packages, follow the right installation tutorials, and report bugs accurately.
Universal Methods: Works on Almost Every Distribution
The most reliable way to check your operating system version in Linux is using commands that adhere to the freedesktop.org standards. These tools are installed by default on virtually all modern systems using systemd.
1. The hostnamectl Command (Recommended)
This is the single most comprehensive command for modern Linux systems. It displays the distribution name, version, kernel version, and hardware architecture in a clean, readable format.
Open your terminal and type:
hostnamectl
Sample Output:
Static hostname: my-laptop
Icon name: computer-laptop
Chassis: laptop
Machine ID: a1b2c3d4e5f6...
Boot ID: f6e5d4c3b2a1...
Operating System: Ubuntu 22.04.3 LTS
Kernel: Linux 6.5.0-14-generic
Architecture: x86-64
Hardware Vendor: Dell Inc.
Hardware Model: XPS 13 9310
Why use it? It requires no flags, works on Ubuntu, Debian, Fedora, RHEL, CentOS, Arch, openSUSE, and more, and clearly separates the Operating System (distro) from the Kernel.
2. The /etc/os-release File (The Standard Source)
If you are writing a script or need a machine-parseable format, hostnamectl essentially reads this file. You can view it directly using cat Surprisingly effective..
cat /etc/os-release
Sample Output:
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
This file is the definitive source for distribution identification. But 04`). Now, key variables to note:
PRETTY_NAME: Best for display purposes. Still, ,22. g.*ID`: The lowercase distro identifier (ubuntu, debian, fedora, rhel, arch).VERSION_ID: Best for version comparison in scripts (e.*VERSION_CODENAME: Essential for adding third-party repositories.
3. The lsb_release Command (LSB Standard)
The Linux Standard Base (LSB) tools provide a consistent interface, though the package (lsb-release) is not always installed by default on minimal installs (like Docker containers or Arch Linux).
lsb_release -a
Flags:
-a: Show all information.-d: Show description only (e.g., "Ubuntu 22.04.3 LTS").-r: Show release number only.-c: Show codename only.
Checking the Kernel Version Specifically
Sometimes you only need the kernel version—for example, when checking if a specific kernel module is supported or debugging hardware regression.
1. uname Command (The Classic Way)
The uname utility prints system information. For the kernel release, use the -r flag.
uname -r
Output: 6.5.0-14-generic
For a full summary including machine hardware name (x86_64, aarch64), use:
uname -a
2. The /proc/version Virtual File
The /proc filesystem exposes kernel data structures. This file provides the kernel version, the GCC version used to compile it, and the compile timestamp.
cat /proc/version
Output: Linux version 6.5.0-14-generic (buildd@lcy02-amd64-047) (gcc (Ubuntu 13.2.0-4ubuntu3) 13.2.0, GNU ld (GNU Binutils for Ubuntu) 2.41) #14-Ubuntu SMP PREEMPT_DYNAMIC...
Distribution-Specific Commands
While the universal methods above cover 99% of use cases, legacy systems or specific enterprise environments might rely on traditional identification files That alone is useful..
Red Hat Family (RHEL, CentOS, Rocky Linux, AlmaLinux, Fedora)
Historically, these distributions used /etc/redhat-release That's the part that actually makes a difference..
cat /etc/redhat-release
Output: Rocky Linux release 9.3 (Blue Onyx)
Note: On modern RHEL/Fedora systems, this file is often a symlink to /etc/os-release or generated for compatibility. hostnamectl remains the preferred method.
Debian Family (Debian, Ubuntu, Linux Mint, Kali)
Debian-based systems traditionally use /etc/issue or /etc/debian_version.
cat /etc/debian_version
Output: 12.2 (This shows the point release of Debian, or the base version for derivatives) And it works..
cat /etc/issue
Output: Ubuntu 22.04.3 LTS \n \l
Warning: /etc/issue is the pre-login banner and can be customized by the admin, making it unreliable for programmatic checks.
Arch Linux and Derivatives (Manjaro, EndeavourOS)
Arch is a rolling release, so it doesn't have a "version number" in the traditional sense (like 22.Worth adding: 04). It has an installation date and a kernel version Took long enough..
cat /etc/arch-release
This file usually exists but is empty; its presence simply identifies the OS as Arch. For the ISO/install media version used, check `/var/log/pacman.log
3. lsb_release – A Structured, Standard‑Compliant Alternative
The lsb_release utility was created to provide a consistent way for scripts to query distribution information without parsing files that vary between releases. It is available in most major distributions, either in the default repositories or via a small package (e.That's why g. , lsb-release on Debian/Ubuntu, redhat-lsb-core on RHEL/Fedora).
lsb_release -a
Typical output
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
ID: ubuntu
The same command works on Red Hat‑based systems, delivering a comparable layout:
Distributor ID: RockyLinux
Description: Rocky Linux release 9.3 (Blue Onyx)
Release: 9.3
Codename: -
ID: rocky
Because lsb_release follows the XDG Base Directory Specification, its output is less prone to accidental edits by administrators, making it a reliable choice for automated discovery.
4. hostnamectl – Systemd’s Unified Query Tool
On any system that runs systemd (the majority of modern Linux distributions), hostnamectl reports not only the kernel version but also the operating‑system identifier, the static, transient, and pretty hostnames, and the locale settings Worth knowing..
hostnamectl status
Sample output
Static hostname: server01.example.com
Transient hostname: server01
Icon name: computer-vm
Chassis: vm
Machine ID: 1234567890abcdef1234567890abcdef
Boot ID: 9abcdef01234567890abcdef12345678
Operating System: Ubuntu 22.04.3 LTS
CPE OS Name: cpe:/o:ubuntu:22.04:patch1
Kernel: Linux 6.5.0-14-generic
Architecture: x86-64
The Operating System line already contains the distribution name and version, while the Kernel line gives the exact kernel release. Because hostnamectl queries the systemd manager, it works uniformly across Ubuntu, Debian, Fedora, openSUSE, and many other systemd‑based distros Easy to understand, harder to ignore..
5. systemd-analyze – Indirect Kernel Insight
While not a direct version identifier, systemd-analyze can reveal the kernel version that the init system booted with. This is useful when troubleshooting boot‑time regressions.
systemd-analyze show | grep Kernel
Result example
Kernel version: 6.5.0-14-generic
The command parses the kernel command line stored in the kernel image, ensuring the information reflects the exact build that the boot loader passed to the kernel.
6. Combining Tools for solid Scripts
A resilient script that must run on heterogeneous hosts often layers several checks:
- Primary –
hostnamectl(systemd) orlsb_release -d(non‑systemd) for a human‑readable description. - Fallback –
cat /proc/versionfor the raw kernel release. - Verification –
uname -rto confirm the kernel version matches expectations.
A minimal Bash snippet that demonstrates this approach:
if command -v hostnamectl >/dev/null 2>&1; then
OS_INFO=$(hostnamectl status | awk -F': ' '/Operating System/ {print $2}')
elif command -v lsb_release >/dev/null 2>&1; then
OS_INFO=$(lsb_release -d | cut -f2)
else
OS_INFO=$(cat /etc/os-release 2>/dev/null | grep PRETTY_NAME | cut -d= -f2 | tr -d '"')
fi
KERNEL=$(uname -r)
echo "Detected OS: $OS_INFO"
echo "Running kernel: $KERNEL"
This pattern ensures that the script works whether the host uses systemd, relies on the older lsb_release utility, or only provides the generic /etc/os-release file.
7. Special Cases and Edge Environments
- Containers – Inside Docker, Podman, or LXC containers, the kernel version reported by
uname -ris the host kernel unless the container is configured with a custom kernel. In such environments,/proc/versionstill reflects the host kernel, whilehostnamectlmay show a truncated OS string. Checking the presence of/sys/fs/cgroupcan confirm containerization. - Live Environments – Many live Linux distributions (e.g., Ubuntu Live, Fedora Silverblue) ship a read‑only root filesystem. In these cases,
/etc/os-releaseis generated at install time and may not be updated when the underlying kernel receives security patches. Relying onuname -ror/proc/versionremains the most accurate method for verifying the running kernel. - Minimal Installations – On stripped‑down systems that lack
lsb_releaseorhostnamectl, the combination of/etc/os-release(if present) and/proc/versionprovides a complete picture without additional dependencies.
8. Summary of Recommended Practices
| Goal | Recommended Command(s) |
|---|---|
| Human‑readable distribution description | hostnamectl status (systemd) or lsb_release -d |
| Exact kernel release | uname -r or cat /proc/version |
| Cross‑distribution script | Combine hostnamectl/lsb_release with uname -r |
| Container or minimal host | Prefer uname -r and /proc/version; avoid reliance on /etc/issue |
| Verification of kernel‑module compatibility | uname -r (kernel) + modinfo <module> (module version) |
Not obvious, but once you see it — you'll see it everywhere.
By following these patterns, developers and system administrators can reliably determine both the operating‑system identity and the kernel version, regardless of the distribution or environment they are working within And that's really what it comes down to..
Conclusion
Understanding how to extract the operating‑system name, its version, and the kernel release is a fundamental skill for anyone managing Linux systems. While classic tools like uname and the /proc/version file remain the most universal, modern utilities such as hostnamectl, lsb_release, and systemd‑based query mechanisms provide cleaner, more maintainable output. Leveraging a combination of these tools—choosing the appropriate one based on the host’s init system and installed packages—ensures reliable, script‑friendly detection across the diverse ecosystem of Linux distributions, containers, and minimal installations Nothing fancy..