How to Remove Old Kernels on Ubuntu

March 11, 2020

Updated on March 16, 2023.

Introduction

A Linux kernel is the core of the operating system. As new versions of Linux are released, your system updates the kernel.

By default, modern Linux versions keep the current kernel, plus one older version. In some instances, Linux doesn’t remove old kernel versions. A common problem when keeping old kernels having an extensive list of bootable images on the GRUB (boot) menu.

This guide will help you remove old and unused Linux kernels on your Ubuntu system (20.04 and 22.04).

Tutorial on how to remove old or unused kernels on Ubuntu 18.04.

Prerequisites

  • A system running Ubuntu (tested on Ubuntu 20.04 and 22.04).
  • A terminal window/command line (Ctrl+Alt+T)
  • A user account with sudo privileges

Removing Old Kernels on Ubuntu

Unused old kernels on Ubuntu take up disk space. Check for old kernel packages with the following command:

dpkg --list | egrep -i --color 'linux-image|linux-headers'
dpkg list linux-headers and linux-images terminal output

The output shows a list of installed kernels with the following flags:

  • ii - Marked for installation (i) and currently installed (i). Packages with these flags are safe to remove.
  • rc - Removed (r) and configuration files present (c). The package is removed, and configuration files require purging.
  • iU - Marked for installation (i) and unpacked (U) to install at the next reboot. Do not remove packages with this flag.

Do not remove any packages that have the current kernel version. To see the current version, use the uname command with the -r flag:

uname -r
uname -r terminal output

There are several ways to remove the old kernel packages from the system.

Using apt autoremove Command

Use the apt command with the autoremove option to automatically remove all old kernels and unrequired packages on the system. Run the following command in the terminal:

sudo apt autoremove --purge

The command keeps only the latest and one prior version on the system.

Note: Alternatively, use the apt-get command for the same results. Read about the difference between apt vs. apt-get.

Using apt remove Command

The apt remove command removes a specified package without removing the dependencies. Use the following commands:

sudo apt remove --purge linux-headers-[version]
sudo apt remove --purge linux-image-[version]
sudo apt remove --purge linux image kernel terminal output

Press Y to confirm the deletion and wait for the process to complete.

Using GUI

GUI and graphical tools providee a simple overview and help prevent costly mistakes. This section focuses on how to remove old kernels using Synaptic. The program is a graphical front-end for the apt package manager.

Follow the steps below to install Synaptic and remove old kernels.

Install and Run Synaptic

1. Install Synaptic with the following:

sudo apt install synaptic -y

The installation takes a few moments to complete.

2. Launch the Synaptic interface from the terminal by typing:

sudo synaptic

The Synaptic Package Manager graphical interface opens in a new window.

Remove Old Kernels

1. Click the Sections button in the left menu.

Location of the Section tab in the Synaptic GUI.

2. Locate the Kernel and modules option on the list.

3. Right-click the kernel to remove in the left menu and select the Mark for Complete Removal option.

Select Kernel and Modules and select the kernels to remove completly.

Synaptic lists additional dependency packages for the kernel.

If necessary the systems infroms you that dependent packages need to be removed as well.

4. Click the Mark option to mark the dependencies for removal.

5. Review the marked packages and click Apply to mark the packages for removal.

The kernels are marked and click the Apply button.

6. Click Apply in the pop-up Summary window to start the removal.

List of changes for you to confirm.

7. A progress bar and the details window show the removal process. Check the box to close the window automatically after removal.

Progress bar for the removal of th old kernels. Process completed.

Alternatively, close the window manually once the removal completes.

Conclusion

You know several methods to remove old kernels from Ubuntu 20.04 or 22.04. Purging old kernels can help you recover wasted disk space in Linux. It’s also considered a best practice to prune out old files and dependencies.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is a technical writer at phoenixNAP who is passionate about programming. Her background in Electrical Engineering and Computing combined with her teaching experience give her the ability to easily explain complex technical concepts through her content.
Next you should read
How to Update Linux Kernel In Ubuntu
December 7, 2023

The Linux kernel is like the central core of the operating system. It works as sort of a mediator, providing...
Read more
How to Check Kernel Version in Linux in Command Line
June 25, 2019

The Linux kernel is much like the central brain of the operating system. Although it is open-source, meaning...
Read more
How to Upgrade Linux Kernel in CentOS 7
October 8, 2019

The Linux kernel is the underlying software architecture of each Linux distribution. It provides and defines...
Read more
How to Check Your Ubuntu Version
July 7, 2019

Finding out which Ubuntu version is running on your system can be important when troubleshooting issues or...
Read more