Remove all old installed but unused kernels

Jul 12, 2013 | Linux, shell, tuts

I just noticed I had 8 kernels installed on a machine. dont need but one…. so I rebooted to make sure I was using the newest, and removed all the old ones via these simple commands :


Ubuntu / Debian / dpkg / Apt:

Thats a one liner, so just copy paste the whole thing.

Centos / RHEL / Yum / RPM:

See which kernel is being used.

get a list of installed kernels

make sure yum-utils is installed

Cleanup old packages, the count can be any number and it will keep that number of the latest packages. count 2 will keep the current newest and one more, 3 will keep the current newest and 2 more and so on.

edit /etc/yum.conf and look for installonly_limit and change it to any number, this was the kernels will be cleaned up automatically. I have mine set to 3.