YUM/DNF Remove Old Kernels on Fedora/CentOS/RHEL

This is quick guide howto delete/remove/clean old kernels on Fedora, CentOS, Red Hat (RHEL). I use here two kernel as example, if you want to keep other more or less, then adjust amount of installed kernels as you wish. Normally reason why you maybe want remove kernels is limited disk space, example on VPS servers and laptop. This is very easy task, you need yum-utils package.

1. Check Installed Kernels

2. Delete / Remove Old Kernels

3. Make Amount of Installed Kernels Permanent

Edit /etc/yum.conf or /etc/dnf/dnf.conf and set installonly_limit:

Share this post

22 Comments

  1. Thank you for your article. Instead of installing yum-utils, why not just use “yum erase” on the kernel packages?

    Reply
    • Hi kkaos,

      You could of course use “yum erase” (from “rpm -q” output), but with yum-utils package-cleanup you can just simply setup count, how many kernels you want to left, without knowing how many kernels you even have. :)

      Reply
      • Execellent answer ;-)

        Reply
  2. If there is a new kernel and update, the older kernel will be deleted automatically after doing this?

    Reply
    • Hi Martín,

      Yes, if you use installonly_limit=[number of kernels] in /etc/yum.conf.

      Reply
  3. thank u .

    Reply
  4. I went to /var/log/yum.log, spotted the installed file, concatenated all in one line, added yum remove before it and pressed enter, job done, the new failed kernel disappeared. In all cases, make sure you have booted from a kernel that’s not the one you intend to erase….

    Reply
    • Hi rolandc,

      Little bit different thing, this guide is removing old kernels and keep amount what you want.

      But yes sometimes it’s useful to remove latest kernel too. Normally I just keep broken kernel also and just boot some another working kernel and wait next kernel build.

      Reply
  5. Short and sweet. I love my Centos.

    Reply
  6. Hi, thanks for the arrticle, I want to know that if I update, I’ll get a new kernel , do I need to install all the softwares or packages I have installed in the old kernel in the new one?

    Reply
    • Hi srinath,

      Could you tell more specific what you have installed in the old kernel? Some packages are compiled automatically when you update kernel.

      Reply
  7. Loaded plugins: product-id, security, subscription-manager
    Updating certificate-based repositories.
    Unable to read consumer identity
    Setting up Install Process
    Nothing to do
    what is this mean??????

    Reply
    • Hi dariush,

      Obviously you are using RHEL, first one question, do you have RHEL subscription?

      Reply
  8. Hello, I was afraid of removing old kernel but you solved my problem, Thanks ya!

    Reply
  9. Very helpful, thanks so much!

    Reply
  10. Simple and succinct! I’ve been doing UNIX/Linux since 1987, and finally there are tools which can self manage their own clean up processes!

    Reply
  11. If you use your examples and have the limit set to 2 and delete all but 2.. then when the next kernel comes out will it even install it since it is already at the limit of two?

    Also do you only have to run package-clean once? and it will maintain that level of kernels from then on? Or is it something you have to run every time you install a kernel to make sure you don’t have too many?

    Reply
    • Hi dv,

      When you have limit set to 2, it will install new kernel and remove oldest and keep 2.

      When you use installonly_limit (Step 3.), then you don’t have to manually run any commands. This package-cleanup command just check current status and remove kernels if needed.

      Reply
  12. Does this also update my grub menu?

    Reply
  13. Thank You, Short, sweet and to the point!

    Reply
  14. Thanks for the helpful information.
    I take it there is no equivalent on CentOS to the automated dnf removal on Fedora?

    Reply

Submit a Comment

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