Home Linux Commands to Check your Linux Kernel Version

Commands to Check your Linux Kernel Version

by admin

What version of Linux am I running? Have you ever been staring at a CLI prompt wondering how to check what version of Linux or which Kernel version you are running on your Linux system? If so, read on, as we will go through a bunch of commands to show you how to get this information.

Get Linux Version Information using hostnamectl

The first command I want to mention is hostnamectl. This command returns a bunch of information about your Linux system and outputs it as a formatted list:

$ hostnamectl
   Static hostname: mylabserver.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: ec2d66dbb1oijiojee4ea351e76ac671
           Boot ID: 27497fe574294fcea99ecd1adff065ec
    Virtualization: kvm
  Operating System: Ubuntu 20.04.3 LTS
            Kernel: Linux 5.11.0-1022-aws
      Architecture: x86-64

The output includes the operating system version, Kernel version, system architecture and more. If we just wanted to check the kernel version we could filter the output using grep:

$ hostnamectl | grep Kernel
            Kernel: Linux 5.11.0-1022-aws;

That may be all you need, but let’s have a look at a few other commands.

List Linux Kernel and System Information with uname

The uname (short for unix name) command can be used to retrieve a bunch of Linux system information. To retrieve the Linux kernel version with uname we can use the -r option:

$ uname -r
5.11.0-1022-aws

You can output other information using uname, depending on which option you use when running the command. To output all the information, including the kernel version, you would use uname -a.

$ uname -a
Linux 9e8b1057721c.mydfer.com 5.11.0-1022-aws #23~20.04.1-Ubuntu SMP Mon Nov 15 14:03:19 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

This output can be a bit confusing at first glance, but it can be broken down as follows:

  • Linux – This is the kernel name
  • 9e8b1057721c.mydfer.com – Hostname for the system
  • .11.0-1022-aws – Kernel release
  • 23~20.04.1-Ubuntu SMP Mon Nov 15 14:03:19 UTC 2021 – Timestamp for the kernel build
  • x86_64 – Machine architecture
  • x86_64 – Processor architecture
  • x86_64 – Operating system architecture
  • GNU/Linux – Operating system

Check Linux kernel version using /proc

There are a few ‘files’ in /proc which contain information on our Linux kernel version. Proc is a virtual filesystem on Linux which contains runtime system information. Many Linux system utilities are calls to files in this directory. For example, lsmod is the same as cat /proc/modules while lspci is the same as cat /proc/pci. Lets have a look at a couple of examples:

$ cat /proc/version
Linux version 5.11.0-1022-aws (buildd@lgw01-amd64-036) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #23~20.04.1-Ubuntu SMP Mon Nov 15 14:03:19 UTC 2021
$ cat /proc/version_signature
Ubuntu 5.11.0-1022.23~20.04.1-aws 5.11.22

You can see the Kernel version 5.11.0-1022 in the output of both commands. Additionally, the first command also tells us about the Linux version – Ubuntu – and some information about the architecture.

How to List Linux Operating System Information

Whilst we are here, a similar question is around how to list Linux operating system information, so I thought it was worthwhile listing a couple of ways to do this here. First of all, there is a file – /etc/os-release – which contains details on the installed operating system. Below is an example of this from an Ubuntu server:

$ cat /etc/os-release
 NAME="Ubuntu"
 VERSION="20.04.3 LTS (Focal Fossa)"
 ID=ubuntu
 ID_LIKE=debian
 PRETTY_NAME="Ubuntu 20.04.3 LTS"
 VERSION_ID="20.04"
 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"
 VERSION_CODENAME=focal
 UBUNTU_CODENAME=focal

Another option here is to use the lsb_release command:

$ lsb_release -a
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.2 LTS
Release:        12.04    
Codename:       precise

Summary

In this tutorial you have seen a number of ways in which you can check the Linux kernel version. We also gave examples of how to list Linux operating system information.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More