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

This is quick guide howto delete/remove/clean old kernels on Fedora 28/27/26, CentOS 7.5/6.10, Red Hat (RHEL) 7.5/6.10. 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.

1. Check Installed Kernels and All Kernel Packages

rpm -qa kernel\* |sort -V
kernel-4.18.9-200.fc28.x86_64
kernel-4.18.10-200.fc28.x86_64
kernel-core-4.18.9-200.fc28.x86_64
kernel-core-4.18.10-200.fc28.x86_64
kernel-devel-4.18.9-200.fc28.x86_64
kernel-devel-4.18.10-200.fc28.x86_64
kernel-headers-4.18.10-200.fc28.x86_64
kernel-modules-4.18.9-200.fc28.x86_64
kernel-modules-4.18.10-200.fc28.x86_64
kernel-modules-extra-4.18.9-200.fc28.x86_64
kernel-modules-extra-4.18.10-200.fc28.x86_64

2. Delete / Remove Old Kernels

2.1 Delete / Remove Old Kernels on Fedora

## dnf repoquery set negative --latest-limit ##
## as how many old kernels you want keep ##
dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)

2.2 Delete / Remove Old Kernels on CentOS / Red Hat (RHEL)

## CentOS, Red Hat (RHEL) ##
yum install yum-utils

## Package-cleanup set count as how many old kernels you want keep ##
package-cleanup --oldkernels --count=2

3. Make Amount of Installed Kernels Permanent on Fedora / CentOS / Red Hat (RHEL)

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

installonly_limit=2

30 comments on “YUM/DNF Remove Old Kernels on Fedora/CentOS/RHEL

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close