How to Check Kernel Version in Linux in Command Line

June 25, 2019

Introduction

Checking the Linux kernel version is essential for ensuring compatibility with both software and hardware. The process verifies the system meets the required specifications for running particular applications.

This tutorial explains how to check the Linux kernel version using five different methods.

How to Check Linux Kernel Version

Prerequisites

  • A system running Linux (this tutorial uses Ubuntu 22.04).
  • Access to the terminal.
  • sudo or root privileges.

How to Check Linux Kernel Version via CLI

There are several ways to check the Linux kernel version via the command line. The following text elaborates on these methods.

uname Command

The uname command without any options displays system information such as the kernel name, network node hostname, kernel release, kernel version, machine hardware architecture, and operating system. When run with the -r option, uname prints the Linux kernel version only.

Check the kernel version by running the following:

uname -r
uname -r terminal output

In this case, the system returns 6.5.0-27-generic. Each number, separated by a dot or hyphen, is part of a kernel version:

  • 6. - The main kernel version represents the overall Linux kernel and represents significant changes and updates to the kernel's architecture, features, and functionality.
  • .5 - The major release version signifies major updates and new features introduced to the kernel.
  • .0 - The minor revision level represents smaller updates, bug fixes, and improvements within the major release.
  • -27 - The level of patches and bug fixes indicates the level of patches, bug fixes, and updates applied to the kernel.
  • generic - The specific configuration of the kernel. In this example, generic refers to a standard kernel configuration compatible with a wide range of hardware and system configurations.

hostnamectl Command

The hostnamectl command is used to discover and change the system hostname and to manage related settings associated with the hostname and system identification. The command also represents one way to print the Linux kernel version.

To check the kernel version, enter the following:

hostnamectl
hostnamectl terminal output

The output shows the current kernel version.

dmesg Command

The dmesg command shows kernel-related messages retrieved from the kernel ring buffer. This buffer stores information about hardware, device driver initialization, and messages from kernel modules, which occur during the system's startup process.

Pipe the dmesg command with grep to get messages related to the kernel version by searching for the keyword Linux version in the output. Run the following:

sudo dmesg | grep "Linux version"
sudo dmesg | grep "Linux version" terminal output

The dmesg command reads the kernel buffer contents, while grep searches for the text Linux version and prints the line that contains that string of characters.

dpkg Command

The dpkg command installs, removes, and manages software packages. It also helps find the Linux kernel version.

To print the kernel version, run the following:

dpkg -l | grep linux-image
dpkg -l | grep linux-image terminal output

The command lists all installed Linux kernel image packages and uses grep to filter and display lines containing the text linux-image. Lines starting with ii indicate installed packages, while rc signifies removed packages with remaining configuration files. In this case, the current installed Linux kernel version is 6.5.0-27-generic.

via /proc/version File

The /proc/version file in Linux provides information about the kernel version, compilation options, and other details related to the operating system's kernel. To display the proc/version file, enter the command:

cat /proc/version
cat /proc/version terminal output

The cat command prints the /proc/version file contents. This outputs the Linux kernel version first, along with additional data about the operating system.

Conclusion

This guide explains several different ways to check the Linux kernel version. Next, learn how to build the Linux kernel step by step.

Was this article helpful?
YesNo
Sofija Simic
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
How to Check Memory Usage in Linux, 5 Simple Commands
March 28, 2024

In this tutorial, learn the five most commonly used commands to check memory usage in Linux. We also provide...
Read more
How to Check the OpenSSL Version Number
March 28, 2024

OpenSSL is an open-source cryptographic library and SSL toolkit. The applications contained in the library...
Read more
Linux Kernel 5.0 Released, New Features & Improvements!
April 3, 2019

The long-awaited Linux Kernel 5.0 upgrade is finally out, and it is time to take a look at all the new...
Read more
How to Update Linux Kernel In Ubuntu
December 7, 2023

The Linux kernel is like the central core of the operating system. It works as sort of a mediator, providing...
Read more