How to install custom kernel on Ubuntu/Debian Linux

The Linux kernel sits at the core of all Linux systems. It is open source and able to be downloaded and compiled by anyone. If you have compiled a custom Linux kernel or downloaded one online, it is easy to install that kernel on an Ubuntu or Debian based systems.

In this tutorial, we will cover the step by step instructions to install a custom kernel on Ubuntu or any Debian based Linux distro. After installation of the kernel, you will be able to boot into it and begin using it right away.

In this tutorial you will learn:

  • How to install prerequisite packages needed to compile kernel
  • How to install a custom Linux kernel on your system
Installing a custom Linux kernel on Ubuntu
Installing a custom Linux kernel on Ubuntu
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Ubuntu Linux or Debian Linux based system
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to install custom kernel on Ubuntu/Debian Linux step by step instructions



  1. The first thing we will do is install the prerequisite packages for compiling and installing a Linux kernel. Open a command line terminal and type the following commands to get started.
    $ sudo apt update
    $ sudo apt install fakeroot build-essential libncurses-dev xz-utils libssl-dev flex libelf-dev bison
    
  2. If you have compiled your own kernel, you can run the following commands from your compling directory to install the Linux kernel and its associated modules.
    $ sudo make modules_install
    $ sudo make install
    

    This will generate the kernel and install it into the /boot directory. Your GRUB boot configuration will also be updated automatically.

  3. In case you have downloaded a precompiled copy of a Linux kernel, which should be several .deb files, you can install the kernel by using the dpkg command on all relevant files.
    $ sudo dpkg -i *.deb
    
    WARNING
    Use caution when installing a custom Linux kernel that you have not compiled yourself. Only do this when you fully trust the source of where you obtained the kernel.
  4. All that’s left to do now is reboot your system and load into the newly installed kernel.
    $ reboot
    
  5. You can verify that your system is indeed using the new kernel by checking the version with this command:
    $ uname -r
    
  6. Bonus step: troubleshooting. In case your system is not booting to the new kernel, you can update initramfs and your GRUB configuration manually with the following commands. Be sure to substitute the kernel version below with that of your own:
    $ sudo update-initramfs -c -k 5.18.2
    $ sudo update-grub
    


Closing Thoughts

In this tutorial, we saw how to install a custom kernel on an Ubuntu or other Debian based Linux system. These steps will allow you to install a Linux kernel that you have customized and compiled yourself. Alternatively, you can install an already compiled kernel from online or a friend, but use caution when doing so.