Easy Guide to Remove Old Linux Kernels on AlmaLinux 8/9

This tutorial intends to show you how to Delete or Remove Old Linux Kernels on AlmaLinux with DNF. The kernel is the bridge between software and hardware, and it is part of an operating system that interacts with the hardware.

In AlmaLinux, old Linux kernels refer to previous versions of the Linux kernel that were installed during system updates or upgrades. During system updates, newer kernel versions are installed, but older ones are often held to provide backup options in case of issues with the new kernel. If you plan to delete a kernel from your server, it is recommended to keep your system updated and install the latest kernel version.

Upgrade AlmaLinux Kernel Version

To install and Upgrade your Kernel version on AlmaLinux servers, you can visit the following guide:

Upgrade Linux Kernel on AlmaLinux

Now you can follow the steps below to display the current kernel version, list all kernels, and Remove Old Linux Kernels on AlmaLinux.

Steps To Remove Old Linux Kernels on AlmaLinux

To complete this guide, you must have access to your server as a root or non-root user with sudo privileges. Then, follow the steps below to use the DNF package manager to delete the old kernels.

Note: To see the difference between DNF and YUm, you can visit this guide on Differences between YUM and DNF package managers.

Step 1 – How To List Current Linux Kernel?

First, you can use the following command to display your current kernel version on your AlmaLinux server:

uname -sr
Linux 6.4.1-1.el8.elrepo.x86_64

How To List All Linux Kernels? At this point, you can run the following command in your Linux terminal to display all available kernels on AlmaLinux or Rocky Linux:

rpm -q kernel

Step 2 – How To Delete Old Unused Linux Kernels on AlmaLinux?

It is recommended to keep at least one or two old kernels if there is a problem with an update.

Now you can use the following command to delete Old Linux Kernels on AlmaLinux:

dnf remove $(dnf repoquery --installonly --latest-limit 2 -q) 

Note: This command will remove all old/unused kernels and keep the currently running and old latest kernel as a backup.

Also, there is another way that you can remove the old kernels. You can edit the YUM config file and set the kernel limit. To do this, open the file with your favorite text editor, we use vi editor:

vi /etc/yum.conf

And set the kernel counts as shown below:

installonly_limit=2		#set kernel count

When you are done, save and close the file. At this point, when you run the system update only two kernels will be left on the system.

sudo dnf update


At this point, you have learned to display the current kernel version, list all kernels, and remove all old Linux kernels on AlmaLinux with the DNF package manager or you can use this step guide to delete unused kernels on Centos.

Hope you enjoy it. Please Subscribe to us on Facebook.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!