Remove old Unused Linux Kernels in Ubuntu

If you are using your Ubuntu system for some long time and keep updating your system to latest, then you will end up a lot of Linux Kernel version installed on your Ubuntu system. During the Linux kernel update the older version of linux kernel not automatically removed. It stays in your system and eating some of your system space. Using the below methods you can remove the old Unused Linux Kernels in Ubuntu system.

Note: Sometimes keeping the old Linux kernel is useful to troubleshoot the current kernel problem. And keep at least one or two old kernels to troubleshoot or fall back.

 

Delete old Unused Linux Kernels in Ubuntu:

Method 1:

Open your terminal and run this command. This is the easiest and safest method and it removes all the unnecessary packages.

sudo apt autoremove --purge

Method 2:

You can also remove the old kernels with terminal manually. But do with caution. First list all installed kernels on your system via this command.

Also Read:  Albafetch System Information Command Line Tool

List all installed Linux Kernels:

dpkg -l | grep linux-image | awk '{print$2}'

You can count total installed linux kernel files using this command.

sudo dpkg --list | egrep -i --color 'linux-image|linux-headers' | wc -l

Then run below command to check your current working Linux kernel version.

Note: Do not remove your current Linux kernel.

uname -r

Important: Do not remove your current Linux kernel.

Now run the below command to remove particular kernel and configuration files. If you want to remove “linux-image-4.10.0-20-generic” then run

sudo apt remove --purge linux-image-4.10.0-20-generic

After that update your grub2 configuration

sudo update-grub2

And finally restart your system.

sudo reboot

You can also remove old Linux kernels via synaptic package manager and Ubuntu software.

If you liked this article, please subscribe to our YouTube Channel. You can also stay connected with us on X (Twitter) and Facebook.



Leave a Reply