You can easily check the currently running Linux kernel in Ubuntu with the following command:
That's well and good. But in Ubuntu, you have more than one Linux kernel installed at a moment.
How do you know which kernels are installed on your system? There is no specific command for that. You can use the package management commands for this purpose.
Let me show you how.
Listing installed Linux kernel on Ubuntu system
Ubuntu uses APT package management system. It can be accessed through the apt, dpkg and aptitude commands. The apt and dpkg commands are what you see in Ubuntu. The aptitude command is more for the Debian systems.
To list the currently available, use the apt command like this:
apt list --installed | grep linux-image
You don't even have to be a sudoer to list the installed kernels.
apt list --installed lists all the packages installed by the
apt commands. You then use the grep command to only show the lines containing
linux-image. The kernels in Ubuntu are named in linux-image-x.y.z format so checking for this specific term gives you the desired result i.e. the list of installed Linux kernels.
For a Ubuntu test server running on Digital Ocean, I see this result:
root@learnubuntu:~# apt list --installed | grep linux-image
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
linux-image-5.15.0-33-generic/jammy-updates,jammy-security,now 5.15.0-33.34 amd64 [installed,auto-removable]
linux-image-5.15.0-39-generic/jammy-updates,jammy-security,now 5.15.0-39.42 amd64 [installed,automatic]
linux-image-5.15.0-40-generic/jammy-updates,now 5.15.0-40.43 amd64 [installed,automatic]
linux-image-virtual/jammy-updates,now 18.104.22.168.42 amd64 [installed,automatic]
As you can see, my Ubuntu system has the following kernels available right now:
linux-image-virtual is basically soft linked to the latest (running) kernel version.
In older days, you would have had several kernels installed with the system updates. Things have changed these days and now Ubuntu only keeps two kernels at a time.
An additional kernel helps you in case there are some issues with the latest kernel and you have to boot into the system with the older one to access the system.
How come I have three kernels when Ubuntu only keeps two kernels at a time?
The kernel "5.15.0-33" is an older one and since I updated but did not reboot the server, it kept on running the old kernel. After the last reboot, 5.15.40 was chosen as the default kernel, 5.15.39 as the additional kernel. At the same time, 5.15.33 is marked to be
auto-removable. If I run the 'apt autoremove' command, kernel 5.15.33 will be removed from the system.
This is the reason why you may see pending kernel upgrade message while updating Ubuntu at times.
That's it. Now you know how to list the Linux kernels installed in your Ubuntu system.