How to remove old kernel versions in Ubuntu

Keeping the Ubuntu system clean and running smoothly often requires some maintenance, one aspect of which is managing old kernel versions. Over time, as the system is updated, multiple kernel versions accumulate, taking up valuable disk space and sometimes causing confusion during boot. Let’s learn the necessary commands to remove old kernel versions in Ubuntu.

1. Check for the installed kernel versions

Before removing old kernels, it’s important to check which kernel versions are currently installed on our system. This will help us identify which ones can be safely removed. We can do that using the following command:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

This command will generate a list of all installed kernel versions on our system. We’ll carefully examine the output to identify the older kernels that we no longer need. As a general rule, we’ll keep the latest kernel version for stability and security and optionally retain one older version as a backup.

2. Remove old kernel versions

Once the old kernel versions have been identified that are no longer needed, we can proceed to remove them using the apt package manager. To do this, we’ll replace x.x.x-generic with the specific version number of the kernel we wish to remove:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

For example, if we want to remove the kernel version 5.4.0-137-generic we can use the following command:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Note: The -y flag in the apt-get install command is used to automatically answer “yes” to all prompts and questions that the installation process might raise.

3. Update the packages

After removing the old kernel versions, it’s a good practice to update the package list to ensure that the system is aware of the latest available software versions:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

4. Autoremove unused packages (Optional)

To remove any unused dependencies, we can run sudo apt autoremove. This will remove packages installed as dependencies for the old kernel versions but are no longer needed.

Remember to exercise caution and double-check the kernel versions removed to avoid unintended consequences.

Let’s try the commands

Now, let’s try to install a linux image and then delete it using the following commands:

  1. List all the installed kernel versions:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
  1. Update the packages:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
  1. Install the Linux image linux-image-5.4.0-137-generic:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
  1. Verify if the Linux image linux-image-5.4.0-137-generic is successfully installed:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
  1. Delete the newly installed Linux image:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Let's practice the commands above in the following terminal to see how the process works:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Conclusion

By following the outlined steps outlined, we can efficiently remove old kernel versions from our Ubuntu system, freeing up valuable disk space and maintaining a clutter-free environment. We have to keep the package list updated and retain at least one backup kernel version to ensure system stability.

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved