By default, modern Linux versions keep the current kernel, plus one older version. However, in some instances, Linux doesn’t remove old versions of the kernel. One common problem of having old kernels is having an extensive list of bootable kernels on the GRUB (boot) menu.
This guide will help you remove old and unused Linux kernels on your Ubuntu system.
- A system running Ubuntu 19.04, 18.04, 16.04
- A terminal window / command line (Ctrl+Alt+T, search > terminal)
- A user account with sudo privileges
Remove Old Kernel Ubuntu 18.04 and 19.04
Display a List of Kernel Versions
To view a list of all kernel versions installed, entering the following:
sudo dpkg ––list | egrep –i ––color ‘linux-image|linux-headers’
The output shows a list of all files labeled linux-image or linux-header. Use this to get an approximate number of old kernels on your system.
You can also count the number of kernels with the command:
sudo dpkg ––list | egrep –i ––color ‘linux-image|linux-headers’ | wc –l
This command displays the total number of both linux-image and linux-headers.
Need to find out which Ubuntu Kernel version is running?
Remove All Old Kernels Using the Command Line
The apt package manager can automatically remove all old kernels. To do so, run the command:
sudo apt-get ––purge autoremove
The system scans for unused kernels and displays a summary of the files it wants to delete. It prompts you to confirm your choice to remove old kernels by pressing
y and Enter to delete.
Manually Remove Individual Kernels from Command-Line
You can manually remove an individual kernel by naming it specifically.
1. First, list the kernels with their installation status:
dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r)
The first two letters for each kernel indicate its status:
- rc – already removed
- ii – installed, eligible for removal
- iU – downloaded and queued for installation
2. Remove a kernel with the
sudo dpkg ––purge [kernel_version]
Make sure you type the exact name and number of the kernel you want to remove. For example:
sudo dpkg ––purge linux-image-5.3.0-28-generic
Use Graphical Tools to Remove Old Kernels in Ubuntu 18.04.
The command-line interface can, at times, be difficult to navigate when working with large sets of data. Using additional graphical tools can give you a better perspective and prevent you from making costly mistakes.
This section focuses on how to remove old kernels using Synaptic and Ubuntu Cleaner on Ubuntu 18.04. These tools can remove a wide variety of unneeded data, such as cached web browser histories, old kernels, and other unwanted software.
How to Remove an Old Kernel with Synaptic
Synaptic is a graphical front-end for the apt package manager, and it allows you to install, remove, and upgrade software packages.
Like most tools of this type, it’s necessary to locate the software packages you intend to remove, mark them for removal, and confirm your choice to complete the removal process.
Install Synaptic by entering the following command in your command line:
sudo apt install synaptic -y
The installation takes a few moments to complete. Launch the Synaptic interface from your terminal by typing:
You now have access to the Synaptic Package Manager graphical interface.
1. Click on the Sections tab.
- Locate the Kernel and modules option from the list.
- Click the Kernel you want to remove and select the Mark for Complete Removal option.
- Synaptic informs you that dependent packages need to be removed as well. Luckily, Synaptic automatically marks them for you once you click the Mark option.
- Review the marked packages and click Apply once you are satisfied.
- To complete the removal process, click Apply in the pop-up Summary window.
- A progress bar allows you to control and review the removal process. Close the window manually once the system informs it has successfully removed the old kernels. Alternatively, check the box to auto close once the process is complete.
How to Remove an Old Kernel with Ubuntu Cleaner
Ubuntu Cleaner allows you to maintain your system at optimal levels by removing unnecessary browser caches, packages, and software installers.
This open-source software is not available from official repositories and needs to be retrieved as a PPA and then installed.
Note: The Personal Package Archives
(PPA) is a specialized software repository intended for non-standard software and software updates.
Enter the following command in your terminal to add the Ubuntu Cleaner PPA:
sudo add-apt-repository ppa:gerardpuig/ppa
After adding the PPA, install Ubuntu Cleaner:
sudo apt install ubuntu-cleaner -y
Once the installations process runs its course, type the following command to access Ubuntu Cleaner:
Use the Ubuntu Cleaner graphical interface to remove the old kernels:
- Check the Old Kernel box.
- Select the kernels you want to remove completely.
- Click the Clean button.
- The Ubuntu Cleaner tool might inform you that other changes are necessary to complete the process. Click Continue if you agree.
- The old kernel removal process is now in progress.
- Once the process is complete, you receive the Cool! Your system is clean! message as confirmation.
How to Delete Old Unused Kernels in Ubuntu 16.04 and Older
By default, previous Linux versions didn’t include tools to manage old kernels.
1. To remove old Linux kernels, you first need to install the byobu tool:
sudo apt-get install byobu
2. Then, run the utility by entering the following:
The utility scans your system and removes all but the latest two kernels. If you want to keep more than the default two, use the
sudo purge-old-kernels ––keep 3 –qy
For more information on the byobu tool, enter the following:
Note: Do not remove the current Linux kernel in use. Doing so could render your system unable to boot. Use the
uname -r command if you need your current kernel version.
Remove Old Kernels Using Ubuntu Software Center
In older versions of Ubuntu, you can remove kernels manually using the Software Center. This option only works if you’re running a graphical interface (GUI).
1. Open the Ubuntu Software Center.
2. Enable the search bar and search for linux-image.
3. In the lower-left corner, you should see a hyperlink for Show xx technical items. Click this link to display the list of Linux kernels.
4. Refer back to your current kernel, which needs to remain on the system. Select any of the older versions and click the Remove button.
5. Refresh the GRUB (boot) menu by entering the following into a terminal window:
Leave at least one previous kernel on your system. Your system was proven to be stable with that kernel. If you have difficulties after a software update, you can revert to the previous (working) Linux kernel.
Note: If you ever encounter a boot failure, visit our guide How to Use Grub Rescue to Fix Linux Boot Failure.
You should now know several methods to remove old kernels from Ubuntu 19.04, 18.04, & 16.04 or older. Purging kernels can help you recover wasted disk space in linux. It’s also considered a best practice for good system hygiene, to prune out old files and dependencies.