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 apt
, yum
, 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
- Free up disk space Linux
- Fixing Compatibility Issues
- Troubleshooting System Problems and Solves System Issues
- Keeps The System Clean While Handling New Linux kernels
- Repair security Issues
- Improve the Performance of the system
- 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:
lists all packages installed on the system sudo apt-get remove linux-image-x.x.x-x-generic
Example :
Removes a specific Linux kernel versionReplace 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:
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:
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.
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 :
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:
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 :
- 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
- Save the script: Save the script in a file, e.g.,
remove_old_kernels.sh
. - Make the script executable:
chmod +x remove_old_kernels.sh
Example :
Run the script with sudo:
sudo ./remove_old_kernels.sh
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.
Similar Reads
How To Uninstall Jenkins On Windows And Linux ?
Jenkins is a popular open-source server automation that is used for continuous integration and continuous delivery (CI/CD) for building, deploying, and automating projects. Jenkins is one of the most popular tools used by DevOps to facilitate server automation tasks. Jenkins is highly extensible and
4 min read
How to Check Kernel Version in Linux
The kernel is the core component of the Linux operating system, responsible for managing hardware, running processes, and ensuring system stability. Whether you're updating software, installing new drivers, or troubleshooting issues, knowing your kernel version helps ensure everything works smoothly
7 min read
How to uninstall packages from Linux?
In this article, we will learn to uninstall the different types of packages from Linux. Let's understand the uninstalling process through some examples: Example 1: Uninstall a package using apt-get In this example, we will remove GIMP, a graphics software that was installed with the help of apt-get.
2 min read
Uninstall Node.JS Using Linux Command Line
To uninstall Node.js from your Linux system, you can use the command line, and the process will vary depending on how you originally installed it. Whether you used a package manager like apt, installed Node.js using nvm (Node Version Manager), or manually installed it from a binary file, you can eas
3 min read
How To Uninstall Specific Version In Numpy
NumPy is a fundamental library in Python programming. In the development of projects, versioning allows development teams to keep track of changes they make to the project code. The changes could be functions, features, bug fixes, and more. So that is managing library versions becomes crucial. With
2 min read
How to uninstall OpenCV in Windows?
OpenCV (Open Source Computer Vision Library) is a powerful open-source computer vision and machine learning software library. While it provides incredible functionality for image processing and analysis, there may come a time when you need to uninstall it from your Windows system. This article will
1 min read
How to Uninstall / Reinstall Cudo Miner in Linux
Cudo Miner is a popular cryptocurrency mining software for Linux. However, if you no longer need it or want to switch to another solution, you may need to fully uninstall it to free up system resources and avoid potential conflicts. This guide provides beginner-friendly steps to completely remove Cu
2 min read
How to Install Older Version of Firefox?
While you download & use any Web Browser, the first preference should be the latest version of the application. The latest version of a browser like Firefox is always the best & has the proper security patches to secure the device where you are using it. However, there are many times when yo
3 min read
How to Uninstall Software from Raspberry Pi Operating System?
Computer science has developed a lot. In earlier days, people used the biggest sized computers. Even at that time, computer monitors are not slim size like modern days. There was no concept of LCD monitors. So, the computer size was extensive along with the size of the monitor. But now, computers ar
4 min read
How to Find openSUSE Linux Version?
openSUSE is well known for its GNU/Linux-based operating systems, mainly Tumbleweed, a tested rolling release, and Leap, a distribution with Long-Term-Support(LTS). MicroOS and Kubic are new transactional, self-contained distributions for use as desktop or container runtime. Here we figure out which
2 min read