Introduction
The Linux kernel is the foundation of the operating system and plays a crucial role in its performance. Linux developers continually enhance the kernel through patches and updates, addressing security, functionality, and speed. Staying current with these developments is vital to ensure the machine operates optimally.
This article teaches you how to update the Linux kernel in Ubuntu using three different methods.
Prerequisites
- An Ubuntu system.
- Access to the terminal.
- A user account with sudo privileges.
Method 1: Use System Update Process
The system update process is a straightforward way to update all packages, including the Linux kernel, to the latest available versions. Before starting, check the current kernel version with the uname command:
uname -r
The output consists of:
- 6.2.0 - The kernel version number.
- 37 - The kernel's specific release or build number.
- generic - Indicates the kernel flavor. The generic flavor is a common choice for regular desktop and server systems.
Step 1: Update System Packages
Use sudo apt update
to update the local package index. The command retrieves information about the latest available package versions from the repositories configured on the system.
Use this command:
sudo apt update
If there’s a newer kernel version, the command finds it and marks it for download and installation. However, the command does not install or upgrade any packages.
Step 2: Run the upgrade
To upgrade the installed packages, including the kernel, to the latest versions available in the repositories, run:
sudo apt upgrade
This command installs the latest Linux kernel version. Verify the changes with uname -r
.
Execute:
uname -r
The output hasn't changed in this case because the kernel was already at its latest version.
Note: If, apart from updating the kernel verion, you're also upgrading to a new Ubuntu release (e.g., moving from Ubuntu 20.04 to 22.04), use sudo apt-get dist-upgrade
. This command handles changes in dependencies and manages major system upgrades.
Method 2: Force Ubuntu Kernel Update with System Update Process
Sometimes, a newer kernel is released but not tested with your Ubuntu version. For instance, a user may use Ubuntu 22.04 and know that Ubuntu 23.10 has a newer kernel version available.
This method allows for upgrading the kernel, but the process requires more work, including backing up important files.
Step 1: Use the Software Updater
After backing up the files, follow these steps:
1. Find the Software Updater by pressing the super key (the Windows key on most keyboards) and searching for it.
2. Launch the Software Updater.
3. Confirm if no updates are needed or if you must perform necessary updates. In our case, the system is up to date.
4. Click the Settings & Livepatch button and proceed to step 2 below.
Step 2: Configure the Software Updater
After clicking the Settings & Livepatch button, a new window appears. Follow these steps to configure settings:
1. Navigate to the Updates tab.
2. Find the Subscribed to drop-down menu and choose All updates.
3. At the bottom of the tab, look for a drop-down menu Notify me of a new Ubuntu version.
4. Choose one of the two and avoid selecting Never:
- For long-term support versions. When stability is critical, and you prefer a more predictable and thoroughly tested environment.
- For any new version. If you are comfortable with occasional changes, enjoy trying out new features, and tolerate potential issues.
5. Close this window and then reopen it. If the system needs updating, the app offers the option to upgrade to the newest version.
Step 3: Force the Upgrade
If the system does not offer an upgrade, force it with:
sudo do-release-upgrade
Note: The sudo do-release-upgrade
command sometimes prints ERROR: failed to read '/etc/update-manager/release-upgrades'
. To fix this, access /etc/update-manager/release-upgrades in your text editor of choice and replace the line Prompt=lts
with Prompt=normal
.
The system displays release notes for the new kernel and Ubuntu versions. For instance, in this example, the terminal shows details about the new Ubuntu version, Ubuntu 23.04 Lunar Lobster.
To upgrade, scroll down to the bottom and choose y to get the latest Ubuntu and kernel versions.
Method 3: Manually Update the Kernel (Advanced Procedure)
To upgrade to the latest (untested) kernel and accept the risks, there’s a third procedure for selecting and installing a new kernel using Mainline.
This user-friendly tool simplifies updating the Linux kernel, but it does not come preinstalled on most Linux systems. Follow the steps for this method in the sections below.
Step 1: Install and Launch Mainline
If you do not have Mainline on your system:
1. Add the PPA maintained by cappelikan to the list of software sources or repositories with:
sudo add-apt-repository ppa:cappelikan/ppa
This PPA is maintained by the user cappelikan and contains the Mainline Kernel Installer. Adding this PPA makes the Mainline software available for installation on the Ubuntu system.
2. Refresh the database with:
sudo apt update
3. Install Mainline with:
sudo apt install mainline
4. Launch Mainline with:
sudo mainline
The Mainline interface launches and displays available Linux kernel versions. If this does not occur, access the interface by hitting the super key (Windows key) and searching for Mainline.
Step 2: Install the Kernel
To get the specific kernel, find it on the list and select it. Next, click the Install button on the right-hand side.
Once the kernel finishes installing, reboot the system.
Step 3: Uninstalling the Kernel
If there’s a problem, select the previous kernel version from the boot screen to revert the process. To do that:
1. Reboot the system and hold the Shift key or Esc key, depending on the Linux distribution.
2. Select Advanced options for Ubuntu.
3. Choose the previous kernel (identified by the version number).
Another way is to use Mainline to remove old kernels on Ubuntu. To do that, click the previously installed (or any older) kernel version and choose Uninstall on the right-hand side.
Conclusion
After reading this tutorial, you now know how to update the Linux kernel using different methods.
Next, learn how to build a Linux kernel from scratch.