Skip to main content
How To

Get Linux Kernel Version in Ubuntu Command Line

Know thy kernel! Here are various ways you can get the currently used kernel version on your Ubuntu system.

Sagar Sharma

"Linux is an Operating System" and I find myself in an unanswerable situation as Linux is the kernel, not OS itself.

It may not seem big of a deal at first glance but the newer kernels are known to bring hardware compatibility for new hardware and improvements.

And using the uname command with the -r option is by far the most popular way of printing kernel version:

uname -r
get linux kernel version using uname command

where uname is a utility to print system info and when used with the -r option, it gets us the kernel version only.

But have you ever wondered what the entire string of Linux kernels indicates? Let me break it down for you.

So my kernel version is 5.15.0-47-generic (in broad terms, I'm running Kernel 5.15).

Where:

  • 5 - Kernel version.
  • 15 - Major version.
  • 0 - Minor version.
  • 47 - Bug fix.
  • generic - It's a distribution-specific string. For Ubuntu, it means I’m using the desktop version. If you're on the Ubuntu server edition, it would be server instead of generic.

This way, you get to know the currently used kernel. But do you know that your Ubuntu systems have more than one kernel version installed at a time?

How to List Installed Kernels in Ubuntu
Ubuntu keeps more than one Linux kernel installed on the system. Here’s how to know which kernel versions are installed on your system.

But wait, there are other interesting ways to get the kernel version and I'm going to discuss them one by one.

Using hostnamectl command

While the hostnamectl command is primarily used to change the hostname, it can also show the kernel version.

How? You may ask.

When the hostnamectl command is used without any options whatsoever, it will print basic details related to hardware and software as given:

hostnamectl command in linux

You can use the grep command to filter unnecessary results as given below:

hostnamectl | grep -i kernel
Filter reults using grep command

Using /proc/version file

As Linux follows the "Everything is a file" philosophy, you'd find files under the /proc directory containing information on the running system. The kernel version is one of them.

It may sound complex but you just have to view the contents of /proc/version file.

cat /proc/version
Using /proc/version file to get linux kernel version

The other details include details such as who compiled your kernel, the compiler used to compile your kernel (GCC) and its version, and the time when it was compiled (11 Aug).

Using Neofetch

Neofetch is a small command line utility that beautifully shows the system information.  

It does not come pre-installed on Ubuntu and can be installed pretty quickly by given command:

sudo apt install neofetch

Once you're done with the installation, you can get the system details, including the kernel version by the following command:

neofetch
neofetch in ubuntu

Unlike me, if you prefer the plain text and required info only (for neofetch only), you can use the grep command to filter results:

neofetch grep -i kernel
use grep command with neofetch

Neofetch can do much more and you can customize it to your liking.

9 Rather Unknown Ways of Using Neofetch in Linux
Neofetch displays the system information and distribution logo in the Linux terminal. It can be tweaked to change its output in surprising new ways.

Using dmesg command

While dmesg is considered a powerful tool to write kernel messages, it can also be used to fetch important details about the system.

Since the dmesg will omit hundreds of lines related to the system, its output must be filtered for our specific use case.

So your dmesg command to get the kernel version will be as follows:

sudo dmesg | grep Linux
use dmesg command to get kernel version

Using inxi Utility

The inxi utility is used to get system information which also includes the kernel version.

But the inxi is not part of the default packages and has to follow the given command to perform the installation:

sudo apt install inxi

The inxi is often used by advanced users as you can get in-depth info about software and hardware. And kernel info falls into the system details part, which can be printed by using -S option.

inxi -S
use inxi utility to print system details

Conclusion

As you can see, there are multiple ways to find the kernel versions in the Ubuntu command line. The most common is the uname command but you can use whichever you find more convenient.

Don't forget that your system has more than one kernel version installed at a time. By default, the newest kernel version is used by the system. Additional kernel versions can be used for recovery and troubleshooting. You can list the installed kernels and verify them.

In a related read, learn about checking the Ubuntu version in use.

Enjoy Ubuntu.

Sagar Sharma