List Installed Linux Kernels and Remove Old ones on Fedora/CentOS

This brief tutorial shows you how to list all installed Linux kernels on Fedora/CentOS and how to remove old ones.

List all installed Linux kernels

Use rpm command with -qa option.

rpm -qa kernel

list installed linux kernels

To check the current running kernel, type this command:

uname -r

Output:

4.4.6-300.fc23.x86_64

Remove Old Kernel

Use dnf remove to remove specific kernels. Example:

sudo dnf remove kernel-4.0.4-301.fc22.x86_64

Output:

Removing:
kernel x86_64 4.0.4-301.fc22 @System 0

Transaction Summary
Remove 1 Package
Is this ok [y/N]: y

Don’t forget to update Grub boot menu:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

CentOS users can install dnf package manager from EPEL repository.

sudo yum install epel-release
sudo yum install dnf

Limit the Number of Kernels on Fedora/CentOS

By default, Fedora and CentOS keep 3 kernels on your system. If you want more old kernels on your system, then edit /etc/yum.conf or /etc/dnf/dnf.conf 

sudo nano /etc/yum.conf
sudo nano /etc/dnf/dnf.conf

Find this line:

installonly_limit=3

Replace 3 by your favorite number. For example, if you like to keep 4 kernels, then change 3 to 4.

That’s it!

Rate this tutorial
[Total: 12 Average: 4.4]

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here