Old Linux kernels can take up a considerable amount of disk space. Apt ("sudo apt-get autoremove") tries to remove uneeded packages, including old Linux kernels, but it may fail to remove all of them.





Apt may fail to remove old Linux kernels when using an Ubuntu version that's under development, if you encounter THIS bug (which still occurs in Trusty), or if you've installed the kernels manually.

There are various commands out there for mass removing old Linux kernels, but they complicated (and hard to remember), and not all are safe. So what's the safest way of mass purging old Linux kernels in Ubuntu? Well, according to Dustin Kirkland, it's the "purge-old-kernels" command.

purge-old-kernels The man page mentions that the command will never remove the currently running kernel. Also, by default, it will keep at least the latest 2 kernels, but you can override this using the "--keep" parameter (for instance "--keep 1" to only keep 1 Linux kernel).





In Ubuntu 16.04 and newer, the purge-old-kernels command is part of the byobu package. For older Ubuntu versions, it's available with the bikeshed package. To install these packages, use the following command:

sudo apt install byobu

sudo apt install bikeshed

Once installed, you can remove old Linux kernels on Ubuntu (or Linux Mint) desktops or servers, using the following command:

sudo purge-old-kernels

via Dustin Kirkland