How to Delete Old Unused Kernels in CentOS, RHEL and Fedora

In this article, we will show how to remove old/unused kernel images on RHEL/CentOS/Fedora systems. However, before you remove an old kernel, it is important to keep your kernel up to date; install the latest version in order to leverage new kernel functions and to protect your system from vulnerabilities that have been discovered in older versions.

To install or upgrade to latest kernel version in RHEL/CentOS/Fedora systems, read this guide:

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

The dnf command you list is wrong still and whoever did the Fedora wiki page is wrong. The below shows that –latest-limit 1 goes from newest to oldest, not the other way around. In F26/F27 package-cleanup does not work and the command you show does not work – it removes the newer kernels.

Does list the older kernel. It looks like =[nospace]-X is required for this to work in F27 at least, the wiki has no = and a space. Positive numbers go from new to old and negative numbers start at the oldest.

My method above is longer but would allow you to pick random kernels for the keep list,

On the other hand, SUSE automatically can maintain a definable number of kernels and purge old kernels automatically if you wish.

Now, SUSE is better tested, automatically tested, is supported better, cheaper, better tooled. You simply are wondering why someone would want to use fedora, centos or rhel. The cool parts that SUSE can accomplish are major version updates without problems. RH 6 to 7? Good luck with that. And SUSE also can do a full upgrade of a service pack, patches and you can fully (!) roll back too. In minutes.

What if you want to remove a newer kernel. I.e. after a kernel update the system crash so you need to use the old one. Can one use this method to remove the newest and unused kernel, not the old one?
Thank you for your excellent articles!