July 22, 2014

How to Clean-Up Old Kernel Packages on Ubuntu

Filed under: Administration — Robert Pope @ 12:09 pm

To purge those old unwanted Linux kernel images after running apt-get install on the latest kernel package, first reboot.
Next, create a file in your home directory and paste the following code in it:

for KERNEL in $(dpkg-query -l | awk '/linux-image-*/ {print $2}' | grep -v --regexp=`uname -r`)
apt-get -y remove --purge $KERNEL
apt-get -y autoremove
apt-get -y autoclean

Make the script file executable, then run it as root via sudo.

When it finishes, reboot again, and you will now have a clean system without all of those useless old kernel packages.

– Robert