Open In App

How to Uninstall Kernel from Linux (Remove Old Kernel Versions)

Last Updated : 10 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The process uninstalling or removing a kernel involves the deletion of a specific kernel version from your Linux System which is aimed at optimizing the performance of the system. Depending on the Linux distribution that one chooses to work with, this process can be executed using various package managers such as aptyum, or Pacman. The Linux kernel is the brain of the operating system that controls the hardware, system processes and secures the system. They provide system stability and performance while managing processes, memory, filesystem, device drivers, and networking as well as handle the scheduling of those processes.

Although it may seem to be difficult, uninstalling a kernel in Linux is actually a simple procedure. Whether you’re looking to free up some disk space, troubleshoot an annoying issue, or just tidy up your system, knowing how to Uninstall an old kernel can be quite handy.

In this article, we have learn about the several methods so that we can safely remove a kernel from the Linux system, so that you can enjoy the new updates

NOTE: Here we will explain how to Uninstall kernels in two different Linux distributions. They are:

  • For Debian/Ubuntu-based Systems
  • For Red Hat/CentOS-based Systems

Reasons for Uninstalling a Kernel from Linux:

Removing a Linux kernel may seem like a drastic step, but there are several valid reasons exist. Here are some common scenarios where you might consider deleting an old or remove unused kernel from your system:

Uninstalling a Linux kernel is indeed a big step. However, there are supportive reasons for undertaking this action. In this article, we see the different ways of removing the kernel from Linux. Here are reasons why we uninstall the kernel from Linux

  1. Free up disk space Linux
  2. Fixing Compatibility Issues
  3. Troubleshooting System Problems and Solves System Issues
  4. Keeps The System Clean While Handling New Linux kernels
  5. Repair security Issues
  6. Improve the Performance of the system
  7. Improve user Experience

Method 1 : Uninstall Kernel from Linux using the Package Manager

Most Linux distributions come with a package manager that simplifies the process of installing and uninstalling software, including kernels. Here’s how to do it using some popular package managers:

1. For Debian/Ubuntu Linux based Systems:

Open your terminal and run the following commands:

dpkg --list | grep linux-image

Example:

Screenshot-from-2025-01-02-19-47-42
lists all packages installed on the system
sudo apt-get remove linux-image-x.x.x-x-generic

Example :

Screenshot-from-2025-01-02-19-54-25
Removes a specific Linux kernel version

Replace x.x.x-x with the version number of the kernel you want to uninstall or remove.

2. For Red Hat/CentOS Linux based Systems:

Use the following command

rpm -qa | grep kernel

Above command lists all installed RPM packages on your system that contain the term "kernel" in their name.

To remove a specific kernel, run:

sudo yum remove kernel-x.x.x-x.el7.x86_64

replace x.x.x-x with the required version.

Method 2 : Uninstall Kernel from Linux using the `apt` Command in Linux

For Ubuntu users, the `apt `command is a more user-friendly alternative to apt-get. To remove or delete an old kernel, you can use:

sudo apt autoremove --purge

Example:

Screenshot-from-2025-01-02-21-21-43

This command removes unused kernels from linux along with their associated configuration files, freeing up disk space and helping to keep your Linux system clean and organized.

To remove a specific kernel version in Linux system, use:

sudo apt remove --purge linux-image-[version]              #Replace [version] with the actual kernel version number.

Method 3: Uninstall the Kernel from Linux using the `dpkg` for Advanced Users in Linux

If you prefer a more hands-on approach for uninstall the Kernel from Linux, you can use `dpkg` directly. First, list all installed kernels:

dpkg --list | grep linux-image

Example:

Screenshot-from-2025-01-02-21-25-39
lists all packages installed on the system

Then, to remove a specific kernel from the Linux system, use:

sudo dpkg --remove linux-image-x.x.x-x-generic

Replace x.x.x-x with required Version.

Screenshot-from-2025-01-02-21-27-18

This method is ideal for users seeking control over uninstalling old kernels from linux, managing kernel removal, freeing up disk space, and safely upgrading to the latest kernel version.

Method 4: Uninstall the Kernel from Linux using the `grubby`on Red Hat-based Linux Systems

For those using Red Hat or CentOS, `grubby` is a handy tool for managing boot entries.

To remove a kernel, first list the installed kernels:

grubby --info=ALL

Then, to remove a specific linux kernel, use:

sudo grubby --remove-kernel=kernel-x.x.x-x.el7.x86_64

This method ensures that the boot-loader is updated accordingly.

Method 5: Manually Uninstall the Kernel from Linux

If you’re feeling adventurous, you can manually uninstall the old kernel versions in your linux system to free up disk space. However, this method for kernel removal in your linux system is not recommended for beginners as it can cause system instability in your linux system. Here’s how to do it:

Step 1: Navigate to the /boot directory.

cd /boot

Step 2: Identify the kernel files you want to delete, such as vmlinuz-x.x.x-x and initrd.img-x.x.x-x, which correspond to outdated Linux kernel versions. To check your current kernel, use:

uname -r

Step 3:Delete the old kernel files using:

sudo rm vmlinuz-x.x.x-x initrd.img-x.x.x-x

Step 4: Update your boot-loader configuration (e.g., run sudo update-grub for Debian-based systems like Ubuntu or Debian).

For safer kernel removal, consider using commands like sudo apt-get autoremove --purge or checking installed kernels with dpkg --list and apt-get purge. These methods help remove unused kernels while maintaining system stability.

NOTE: Manual removal can be risky, so it’s better suited for advanced users managing Linux kernels or updating them efficiently. Always verify kernel versions in the /boot directory before proceeding.

Method 6: Using the GUI Tools to Uninstall Kernel from Linux

If you prefer a graphical interface, many Linux distributions offer GUI tools for managing installed kernels.

For example, in Ubuntu, you can use the "Software & Updates" application to easily remove old kernel versions or uninstall the Kernel from Linux without using terminal commands. Navigate to the "Installed" tab, select the kernel version you want to remove, and click "Remove."

Note: Alternatively, in Debian or Ubuntu, advanced users can manage kernels with commands like apt-get purge or dpkg --list to review installed Linux kernel versions. To safely clean up the /boot directory, you can use sudo apt-get autoremove --purge to remove unused kernels. Keeping only necessary kernels ensures better system performance, simplifies Linux kernel updates, and makes managing Linux kernels more efficient.

Example :

Screenshot-from-2025-01-02-21-38-36

Method 7: Using uname to find the Current Kernel version in Linux system

Before uninstalling a kernel, it’s crucial to ensure you’re not removing the one currently in use. You can check your current kernel version in your Linux distro with:

uname -r

Example:

Screenshot-from-2025-01-02-21-43-29

Make sure to avoid uninstalling this version to prevent boot issues. In Ubuntu and Debian, ensure you don’t delete the current kernel version by mistake. Once you've identified the kernel to remove, use sudo apt-get autoremove --purge to delete old kernel Linux files and clean up the /boot directory. This will help you remove unused kernel versions and maintain an up-to-date system with proper Linux kernel removal.

Method 8: Using Synaptic Package Manager to Uninstall the Kernel from Linux

The Synaptic Package Manager is a graphical tool for Debian-based Linux distributions, providing an intuitive way to install, upgrade, or remove software packages, including Linux kernel removal tasks. With Synaptic, you can efficiently manage Linux kernel versions and perform actions like uninstalling old kernels to free up space in the /boot directory.

Install Synaptic if you haven't already.

 sudo apt install synaptic

Example :

Screenshot-from-2025-01-02-21-45-46
  • Open Synaptic and search for linux-image or linux-headers to find installed Linux kernel versions.
  • Right-click the kernel you want to uninstall and select "Mark for Complete Removal" to ensure a thorough cleanup.
  • Click "Apply" to remove old Linux kernels and associated files.

Note: This approach is ideal for users seeking to remove unused kernel versions, perform Linux kernel updates, or manage kernels efficiently in Ubuntu or Debian systems.

Method 9: Using Command Line Script for Uninstalling the Kernel

You can also use a script to automate the removal of old kernels from the linux system. Here’s a simple script that keeps the current and the last two kernels.

#!/bin/bash
# Ensure the script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or with sudo."
exit
fi
# Get the currently running kernel version
current_kernel=$(uname -r)
echo "Currently running kernel: $current_kernel"
# List all installed kernels
echo "Installed kernels:
"dpkg --list | grep linux-image | awk '{print $2}'
# Remove old kernels except the currently running one
echo "Removing old kernels..."
dpkg --list | grep linux-image | awk '{print $2}' | grep -v "$current_kernel" | xargs sudo apt-get -y purge# Update the bootloaderecho "Updating GRUB..."sudo update-grubecho "Old kernels removed successfully!"

Steps to Use the Script

  1. Save the script: Save the script in a file, e.g., remove_old_kernels.sh.
  2. Make the script executable:
    chmod +x remove_old_kernels.sh

Example :

Screenshot-from-2025-01-03-14-18-52

Run the script with sudo:

sudo ./remove_old_kernels.sh
Screenshot-from-2025-01-03-14-16-09

Uninstall Kernel from Linux: Post-Removal Steps

Now check whether your Kernel is successfully uninstall/ deleted from your linux system:

Step 1: Verifying Removal

After completing the Linux kernel removal, it’s crucial to verify that the unnecessary kernels are successfully deleted. Use the following command to check installed kernel versions:

dpkg --list | grep linux-image

This command lists all the remaining Linux kernel versions installed on your system. Confirm that only the active kernel (you can check this with uname -r) and necessary headers remain, ensuring that the remove old kernel versions process was successful. This step is particularly helpful for users on Ubuntu or Debian to avoid any clutter in the /boot directory.

Step 2: Rebooting

If a new kernel version has become the default after the Linux kernel update, a reboot might be necessary for the changes to take full effect. Ensure that you’ve followed proper procedures to remove unused kernels safely before rebooting. Use sudo apt-get autoremove --purge to clean up any residual files and free up space in the /boot directory

Tips for Managing Kernels in linux:

  • Retain the Last Two Kernels: Always keep at least one or two older kernels as backups in case the current kernel encounters issues.
  • Avoid Manual Deletion: Do not manually delete kernel files from /boot. Use package management tools like apt-get purge or commands such as sudo apt-get autoremove --purge to ensure dependencies and configurations are handled correctly.
  • Schedule Regular Cleanup: Automate the process to remove unused kernel versions and clean the /boot directory regularly, ensuring smoother Linux kernel updates.
  • Expert Advice : If you're unsure how to uninstall a kernel version from the linux system, consult Linux experts or refer to official documentation to avoid errors during Linux kernel removal.

Conclusion

Uninstalling Kernel from Linux is straightforward but requires caution. Always check your active kernel using uname -r and remove only outdated or unused versions like old kernel versions in Ubuntu or Debian using commands like dpkg --list or sudo apt-get autoremove --purge. Afterward, update your bootloader to reflect the changes.

With proper Linux kernel management, including regularly deleting old kernel Linux versions and retaining important backups, you can maintain a clean, efficient system with optimized performance and seamless updates.


Next Article
Article Tags :

Similar Reads