HOWTO · Linux
How to Check Kernel Version in Linux
This article provides a comprehensive guide on how to check the running kernel version in Linux. Learn various methods, including using commands like uname, dmesg, and hostnamectl, to easily access kernel information. Ideal for system administrators, developers, and Linux enthusiasts, this guide ensures you have the knowledge to manage your system effectively.
On this page
To identify the Linux kernel currently running on a machine, start with uname -r. Other commands expose build details, a broader system summary, or boot-message context. Choose the result that answers your question: checking a release string does not install or update a kernel.
Check the Running Kernel Version with uname -r
Run this command:
uname -r
The command prints the release identifier for the running kernel, commonly in a form such as 5.15.0-xx-generic. The numeric components identify a release line, while suffixes can carry distribution or build-specific information. Their format and meaning vary, so do not assume every suffix has the same interpretation across Linux distributions. This is usually the quickest answer when checking compatibility requirements or reporting which kernel is active.
Read Kernel Build Details from /proc/version
The virtual file /proc/version gives a longer description that includes the kernel release and build-related details. Use cat to read it:
if [ -r /proc/version ]; then cat /proc/version; else printf '%s\n' '/proc/version is not readable here'; fi
Look for the text following Linux version to identify the release. The remaining text may identify the build account, compiler, and build information. Exact fields depend on how the kernel was built. This file is useful when a short value from uname -r is not enough and you need additional build context; it is not a substitute for distribution-specific package records.
Check Kernel Information with hostnamectl
On systems that provide systemd’s hostnamectl, the command reports host details as well as a Kernel field. This example captures command errors and reports them as text, so a missing system service does not leave a failed command or an unreported diagnostic:
if command -v hostnamectl >/dev/null 2>&1; then
if details=$(hostnamectl 2>&1); then
printf '%s\n' "$details"
else
status=$?
printf 'hostnamectl failed (exit %s):\n%s\n' "$status" "$details"
fi
else
printf '%s\n' 'hostnamectl is not available'
fi
When the command succeeds, find the line labeled Kernel and read the release after it. If the reported failure says it cannot connect to the system bus, the system manager is unavailable in that environment; use uname -r for the current release instead. hostnamectl is convenient when you also want operating-system and architecture information, but its system summary is less concise than uname -r.
Find Kernel Information in Boot Messages with dmesg
dmesg reads the kernel ring buffer, which may include a boot-time line beginning with Linux version. Availability of older boot messages and permission to read the buffer vary by system. This guarded example searches for a matching line and avoids treating unavailable or restricted access as a successful lookup:
if command -v dmesg >/dev/null 2>&1; then
messages=$(dmesg 2>/dev/null) || messages=
match=$(printf '%s\n' "$messages" | grep -m 1 'Linux version' || true)
if [ -n "$match" ]; then printf '%s\n' "$match"; else printf '%s\n' 'No readable Linux version line found in the kernel buffer'; fi
else
printf '%s\n' 'dmesg is not available'
fi
If the search finds no line, that does not by itself mean the system lacks a kernel version; the buffer may be restricted, cleared, or simply not contain a matching message. Use uname -r for the direct current-release check and treat dmesg as an optional source of boot context.
Choose a Method for Your Task
Use uname -r when you need a short identifier for the running kernel. Read /proc/version when compiler or build details are relevant. Choose hostnamectl for a wider host summary that includes the kernel field, and try dmesg when the boot message itself matters and the buffer is accessible. These methods describe the running system; they do not tell you which kernel packages are installed but inactive.
For a remote Linux server, connect with SSH first, then run the same command in that remote shell. The result describes the server, not the computer from which you connected. If you are checking compatibility, compare the release or build detail your software requires with the value reported by the target machine.