Skip to main content
How To

Install Mainline Linux Kernel in Ubuntu Command Line

Want to install the latest mainline Linux kernel in Ubuntu? Here's a handy utility that lets you easily install it.

Sagar Sharma

Usually, you should stuck with the kernel version Ubuntu provides. However, if you have noticed a bug or some hardware not being supported with the current kernel version, you can try upgrading the kernel and use the latest one.

Yes! Ubuntu gives you the ability to install a newer mainline kernel. You can download your preferred version from the archive here and install the deb files.

However, there is an unofficial PPA that lets you install the newer kernel easily.

So in this guide, I will be covering:

  • Install the latest mainline kernel
  • Install the latest point release
  • Use old kernel by default for system boot

How to install mainline kernel in Ubuntu

To install the mainline kernel, you'd need a package named mainline.

But it is not available in the default repositories in Ubuntu so in that case, using PPA is the right choice when the package is not available in the default repository.

To add PPA for the mainline package, use the following command:

sudo add-apt-repository ppa:cappelikan/ppa

Now, use the following command to update the repository and install the mainline utility:

sudo apt update && sudo apt install mainline

Once you are done with the installation, you can check the available latest mainline and the point release using the following command:

mainline --check
check the latest mainline kernel availabe for Ubuntu

For me,

  • The latest mainline kernel is 6.1.9
  • And the latest point release is 5.15.91

You can go with either of them or install both as you can choose one while the system boot.

So I will share how to install both of them one by one.

Install the latest mainline kernel in Ubuntu

To install the latest mainline kernel, all you have to do is execute the following command:

sudo mainline --install-latest
install the latest mainline kernel in Ubuntu

Once done, reboot your Ubuntu machine to have the effect from the latest kernel:

reboot

And as you can see, when I checked for the currently running kernel, it indicated that I'm running the most recent kernel 6.1.9:

uname -r
check kernel version in Ubuntu

Install the latest Linux kernel point release in Ubuntu

To install the latest kernel point release, use the following command:

sudo mainline --install-point

And you have the latest point release.

But if you have the latest mainline kernel and latest point release, your system will choose the latest kernel to boot.

For that, you'd have to choose your kernel version while the system boots.

Reboot your system and at the grub screen, choose the Advanced options for Ubuntu and select the kernel version:

Select specific kernel to boot in Ubuntu

You can use the same method if you have installed multiple kernels and want to use specific ones at a time.

Make the old kernel default in Ubuntu

If you have multiple kernels installed on Ubuntu, your system will boot with the most recent kernel.

And you may not want the latest kernel all the time.

But don't worry, you don't have to remove the latest kernel, you can make your preferred kernel a default choice.

First, reboot your system, and at the GRUB screen perform:

  • Select Advanced options for Ubuntu
  • Select the kernel you want to make a default choice for every boot.

Once you perform the above steps, you will boot with the old kernel.

I know it's a temporary solution. But you can't the old kernel a default choice without booting from it.

Once you boot into the kernel of your choice, open the grub config file using the given command:

sudo nano /etc/default/grub

And add the following two lines to the grub config file:

GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
make old kernel default choice to boot in Ubuntu

Save changes and exit from the nano text editor.

Now, to enable the changes you just made, you will have to update the grub on Ubuntu:

sudo update-grub

That's it! The kernel you are currently using is not the default option.

But if this sounds too complex, you achieve the same results with GUI:

How to Boot into an Older Kernel By Default in Ubuntu and Other Linux
Here’s a possible scenario. Your system received a kernel update but somehow things are not working as smoothly as previously. You realized that if you boot into the older kernel (yes, you can downgrade kernel), things are back to normal. That makes you happy with a little inconvenience. Y…

Wrapping Up

This was a quick guide on how you can install the latest mainline kernel on Ubuntu.

I hope you will find this guide helpful and if you have any queries, let me know in the comments.

Sagar Sharma