How to Install and Compile Kernel in Debian

One of the biggest draws to using Linux is its easy customization and one of the most fun things to customize is the Kernel itself, the heart of the Linux operating system.

Chances are that you will most likely never have to compile your own kernel. The one that ships with your distribution and updates via your package management system is usually good enough, but there are times when it might be necessary to recompile the kernel.

Some of these reasons might be special hardware needs, the desire to create a monolithic kernel instead of a modularized one, optimizing the kernel by removing useless drivers, running a development kernel, or simply learning more about Linux.

In this case, we are going to compile a newly released kernel on Debian systems that includes several new features, such as new drivers for the graphics cards, and offers significant improvements to the filesystem.

How to Compile Kernel in Debian

To get started, we are going to need some packages, namely build-essential and kernel headers.

sudo apt update
sudo apt install build-essential linux-headers-$(uname -r)

Now, visit the official kernel website to download the desired kernel version. Alternatively, you can use the following commands to download the source directly.

tar -xvf linux-6.7.tar.xz
cd linux-6.7/

Now, we will need to configure the kernel, it is advisable to begin with the configuration currently in use and build upon it. To accomplish this, we’ll copy the existing configuration from the /boot directory to the current working directory and save it as .config.

cp /boot/config-`uname -r` .config

To start with the actual configuration process, you have one of two options.

  1. If you have X11 installed, you can run make xconfig, and have a nice GUI menu to assist you as you configure your Kernel.
  2. If you are running in a CLI environment, you can run make menuconfig, but it will need the libncurses5-dev package installed to use it.

If you are going with a cli environment, make sure to install the libncurses5-dev package to start the kernel configuration process as shown.

apt install libncurses5-dev
make menuconfig
Kernel Configuration Menu
Kernel Configuration Menu

As you will see, once you are in the configuration of your choice, there are a ton of different options available for your Kernel. In fact, there are far too many for the scope of this tutorial.

When selecting Kernel options, the best way is by trial and error, and doing plenty of Googling, which is the best way to learn. If you are simply just trying to update your Kernel to the most recent version, you don’t have to change anything and can simply select “Save Configuration”. Since we copied the current kernel’s configuration file to the new kernel’s .config file.

Save Kernel Configuration
Save Kernel Configuration

Be mindful that “Kernel module loader” is selected in “Loadable module support”. If it is not, and you are using kernel modules, it can seriously mess things up.

Kernel Module Support
Kernel Module Support

Now initiate the kernel compilation process using the following commands, which will compile the kernel, install modules, and copy the necessary files to the boot directory.

make modules_install
make install

Once installed, you simply reboot, and select the new kernel from your GRUB menu.

Debian New Kernel
Debian New Kernel

Be sure to pay close attention to any error messages during the boot process so you can troubleshoot any issues.

To check the new kernel version in Debian, you can use the following command in the terminal.

uname -r

If you want to see a list of installed kernels, you can check the contents of the /boot directory:

ls /boot
Check Kernel Version
Check Kernel Version

Remove Old Kernel in Debian

To remove old kernels in Debian, first you need to list the installed kernels to identify the ones you want to remove using the dpkg command.

dpkg --list | grep linux-image

To remove an old kernel, use the following apt command and make sure to replace linux-image-OLD_VERSION with the version number of the kernel you want to remove.

sudo apt purge linux-image-OLD_VERSION
Remove Old Debian Kernel
Remove Old Debian Kernel

After removing the old kernels, update GRUB to reflect the changes.


In conclusion, compiling a kernel in Debian is a valuable skill that allows users to tailor their operating system to specific needs, incorporating the latest features and optimizations.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Rob Krul
Rob is an avid user of Linux and Open Source Software, with over 15 years experience in the tech geek universe. Aside from experimenting with the many flavors of Linux, he enjoys working with BSDs, Solaris, and OS X. He currently works as an Independent IT Contractor.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.


Leave a Reply
  1. try “ls /boot/”

    there’re one or more config files.
    Copying previous config into new kernel build directory for your convenience.

  2. make-kpkg has been deprecated for years. Linux includes a debian package target in their stock makefile since 2.6.3x at least. Everything up to that point is fine, but tell your readers to ‘make deb-pkg’ instead. That also makes the concurrency easier since it’s just make, and it takes standard make options like -j.

    for more information:

  3. The error with command “# cp /boot/config-`uname –r`.config” is in “-r” part. Delete the “-” before the “r” and write it again. You will see the diference.


  4. I found your guide ~2 months ago and it was the trigger for me to build my first kernel, since it looked so easy. Before, I refrained from trying it simply because I was afraid I could not use apt to manage my homebrew kernel mess. ;-)

    I keep my kernel updated this way ever since, using a simple scriptified version of your guide:

    So, thank you alot!


  5. `/boot/config-uname -r*.config’ is not working
    you have latest working config copy to the sources like this:

    cp /boot/config-3.blabala /your/linux/sources/folder .config

  6. Thank you for this guide!
    it´s very helpfull and save a lot of nerves ;)
    btw: if you have trouble with error timestamp errorcode 2

    apt-get install bc



  7. Thanks a million for this guide. Clear, concise, easy to understand. After browsing thorugh “Devian handbooks” and whatnot, I finally managed to compile my custom Kernel after reading this!

  8. hello.
    i wanted to install libraries using apt-get install command but its showing command not found. could just tell me which software package to be downloaded…

  9. I get the following message.

    root@debian:/home/bill# cd linux-3.12
    root@debian:/home/bill/linux-3.12# cp /boot/config-‘uname -r’*.config
    cp: missing destination file operand after `/boot/config-uname -r*.config’
    Try `cp –help’ for more information.

    Can you help?


  10. Hi

    I am getting errors when install debs. Any recommendations?

    Error! Bad return status for module build on kernel: 3.12.2-customkernel (i686)

  11. Thanks, great article.
    My first kernel compilation was on 1999…. (on a RedHat 6.0..a lot on time since that days), but the process and some concepts behind has not changed too much.
    I’m a Debian user since 2001 and currently using a custom (and optimized) kernel 3.11 for an Asus A45VJ.

    thanks again and greetings from Chile.

  12. hi!
    I’ve run the make menuconfig but get an error:
    HOSTCC scripts/basic/fixdep
    /bin/sh: 1: scripts/basic/fixdep: Permission denied
    make[1]: *** [scripts/basic/fixdep] error 126
    make: *** [scripts_basic] error 2

    I am running with ‘su’ command and in the /dev/shm directory
    Thanks a lot!

  13. Hi!

    Thanks for the guide, it’s great, but i have a question.
    I use LMDE with 3.10 kernel and it’s not works perfectly. Sometimes couldn’t boot. So if I compile the 3.12 kernel I should copy the previous config from the /boot or I configure it with the menuconfig?

  14. @Lars

    The Nvidia driver itself is not included with the kernel source. You have to get the driver from Nvidia and install it. I’m going to write a how to for this tonight, and it should be published tomorrow or the next day.

    The article was a little unclear with this. It was supposed to read “support for Nvidia Optimus” but I forgot to add “support”. I will let the editor know.

    The new kernel allows you to run the Optimus driver natively, without having to rely on Bumblebee for added functionality. With the new kernel, you have access to things like GPU switching and so forth.

    Sorry if I created any confusion.

  15. Thanks for the neat guide!
    I think there is a typo in the line “cp /boot/config-`uname -r` .config”.
    Doesn’t that have to be “cp /boot/config-`uname -r`* .config” instead?
    Anyway, many thanks for putting it together and publishing.



Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.