How to compile the latest Linux kernel

Compiling the Linux kernel allows you to customize your system, use the latest features, or optimize performance.

Note: This guide is based on Ubuntu. Some commands may be different if you are using a different Linux distribution.

Install required tools

To compile the Linux kernel, you need these packages installed on your system:

sudo apt update
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev

Download the Latest Kernel Source Code

Get the latest Linux kernel source code from the official repository:

git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux

Configure the Kernel

Copy the configuration of your current running kernel:

cp /boot/config-$(uname -r) .config

Then update the configuration if you’d like to change something:

make menuconfig

Once you’re done, save your changes and move to the next step.

Compile and install the Kernel

Compile the kernel:

make -j$(nproc)

Compile the modules:

make modules -j$(nproc)

Install the modules:

sudo make modules_install

Install the kernel image:

sudo make install

Update Bootloader

Regenerate the GRUB configuration to include the new kernel:

sudo update-grub

Boot into the New Kernel

Reboot your system and select the new kernel:

sudo reboot

Verify the running kernel version:

uname -r

The output should look something like this:

bojan@ubuntu-2404-arm:~$ uname -r
bojan@ubuntu-2404-arm:~$ 6.13.0-rc7+

Congrats, you just compiled and booted the latest Linux kernel!


Find this post helpful? Subscribe and get notified when I post something new!