When you are debugging drivers like you do, you may want to know which Linux kernel version your system is using? Here are three ways to check the kernel version in the Linux terminal.
I am using Ubuntu at the time of writing this article, but these commands are generic and can be used on Fedora, Debian, CentOS, SUSE Linux or any other Linux distribution.
Using the uname command to find the Linux kernel version
uname is a Linux command used to get information about your system. You can also use it to determine whether you are using a 32-bit or 64-bit system.
Open a terminal and type the following command.
The output will be similar to the following.
This means that you are running Linux kernel 4.4.0-97, or more generally, that you are running Linux kernel version 4.4.
But what do the other numbers here mean?
- 4 - kernel version
- 4 - major revision
- 0 - minor revision
- 97 - bug fixes
- generic - A distribution-specific string. For Ubuntu, this means that I am using the desktop version. For Ubuntu server versions, it will be server.
You can also use the uname command with the option -a. This will give you more information about your system if you need it.
The output of the command should look like this.
Let me look at the output and what it means.
- Linux - kernel name. If you run the same command on BSD or macOS, the result will be different.
- myfreax - The host name.
- 4.4.0-97-generic - Kernel version (as we saw above).
- #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017 - This means that Ubuntu has compiled 4.4.0-97-generic 120 times. The timestamp of the last compilation is also there.
- x86_64 - Machine architecture.
- x86_64 - Processor architecture.
- x86_64 - Operating system architecture (you can run a 32-bit operating system on a 64-bit processor).
- GNU/Linux - operating system.
Let’s look at some other commands to find your Linux kernel version.
Using the /proc/version file to find the Linux kernel
In Linux you can also find kernel information in the file /proc/version. We can take a look at the contents of this file using the cat command.
You will see output similar to that seen with uname.
You can view the kernel version 4.4.0-97-generic here.
Using the dmesg command to find the Linux kernel version
dmesg is a powerful command for writing kernel messages. It is also very useful for getting system information.
Since dmesg provides a lot of information, you should normally use a command such as less to read it. However, since we are only here to check the Linux kernel version, grepping on “Linux” should provide the required output.
The output will be a few lines long, but you should be able to easily identify the Linux kernel version.
Of the three methods discussed here, uname is the most convenient. Reading /proc/version directly is suitable for use when writing programs. dmesg command this we generally rarely use.