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

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.95/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

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.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

10 Responses

  1. Jason says:

    In Fedora 26 this worked:

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

  2. Michael says:
    $ sudo dnf remove $(dnf repoquery --installonly --latest-limit 2 -q)

    Problem: The operation would result in removing the following protected packages: kernel-core

    That is because

    $ dnf repoquery --installonly --latest-limit 2 -q

    Lists your current kernel

    $ sudo dnf remove $(rpm -qa | awk '/^kernel/' | grep -v $(uname -r))

    Seems like a safer alternative.

  3. N30xMind says:

    Hi Aaron,

    Under Remove Old/Unused Kernels On Fedora. In the below command -2 hyphen must be removed in order for the command to work.

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

    It should be,

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

    Thank you

  4. R. Hell says:

    “Attention: On the contrary, is recommended to keep at least one or two old kernels to fall back to in case there is a problem with an update”

    I fully agree on that. And you know why? Well.. RedHat managed to get the following bug to exist since 2015 and still not being fixed fully.

    So yes, you need to be sure that you keep something that works.

    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.

    • Aaron Kili says:

      @R. Hell

      Thanks for the useful insights on openSUSE, i suppose it’s high time i started using it to realize some of the benefits you have mentioned above. Once again, many thanks for writing back.

  5. Mauricio López says:

    Hey Aaron,

    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!

    • Aaron Kili says:


      Not really, you can run this command to remove a kernel(preferably a new kernel):

      #yum remove kernel-4.12.10-1.el7.elrepo.x86_64


      #rpm – -erase kernel-4.12.10-1.el7.elrepo.x86_64

      Finally, thanks too for the useful feedback.

Leave a Reply to Aaron Kili Cancel reply

Your email address will not be published. Required fields are marked *