How to Install Kernel Headers in Ubuntu and Debian

In our last article, we have explained how to install kernel headers in CentOS 7. Kernel Headers contain the C header files for the Linux kernel, which offers the various function and structure definitions required when compiling any code that interfaces with the kernel, such as kernel modules or device drivers and some user programs.

It is very important to note that the kernel headers package you install should match with the currently installed kernel version on your system. If your kernel version ships with the default distribution installation or you have upgraded your Kernel using dpkg or apt package manager from the Ubuntu or Debian base repositories, then you must install matching kernel headers using package manager only. And if you’ve compiled kernel from sources, you must also install kernel headers from sources.

In this article, we will explain how to install Kernel Headers in Ubuntu and Debian Linux distributions using default package manager.

Install Kernel Headers in Ubuntu and Debian

First check your installed kernel version as well as kernel header package that matches your kernel version using following commands.

$ uname -r
$ apt search linux-headers-$(uname -r)
Check Kernel Version and Kernel Headers in Ubuntu
Check Kernel Version and Kernel Headers in Ubuntu

On Debian, Ubuntu and their derivatives, all kernel header files can be found under /usr/src directory. You can check if the matching kernel headers for your kernel version are already installed on your system using the following command.

$ ls -l /usr/src/linux-headers-$(uname -r)
Check Kernel Headers in Ubuntu
Check Kernel Headers in Ubuntu

From the above output, it’s clear that the matching kernel header directory doesn’t exist, meaning the package is not yet installed.

Before you can install the appropriate kernel headers, update your packages index, in order to grab information about the latest package releases, using the following command.

$ sudo apt update

Then run the following command that follows to install the Linux Kernel headers package for your kernel version.

$ sudo apt install linux-headers-$(uname -r)
Install Kernel Headers in Ubuntu
Install Kernel Headers in Ubuntu

Next, check if the matching kernel headers have been installed on your system using the following command

$ ls -l /usr/src/linux-headers-$(uname -r)
Verify Installed Kernel Headers in Ubuntu
Verify Installed Kernel Headers in Ubuntu

That’s all! In this article, we have explained how to install kernel headers in Ubuntu and Debian Linux and other distributions in the Debian family tree.

Always keep in mind that to compile a kernel module, you will need the Linux kernel headers. If you have any quires, or thoughts to share, use the comment form below to reach us.

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!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

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.

19 Comments

Leave a Reply
  1. My problem with this install is that my laptop is “offline” (no internet access at all).

    I need a way to download them to another device and take them back to the insulated device.

    How may I carry out that?

    Reply
  2. Any way to specify the source path where debian is searching for linux headers? mine searches for cdroom drive path, but I don’t even have a cd rom. I’d rather use a flash drive directory with extracted debian iso.

    Reply
    • @Devlabs,

      To install Linux Headers on Debian, use the following commands…

      # apt update
      # apt upgrade
      # apt dist-upgrade
      # reboot
      # apt install linux-headers-$(uname -r)
      
      Reply
      • I made my Debian not work when I pasted in # reboot. It got stuck, so I pressed x and then went back to the terminal.

        It said to me:

        ERROR vsh: [vsh.cc(239)] Poll timed out after waiting 5 seconds.

        And now I think I have to powerwash it because it does not let me type anything at all. Do I actually have to powerwash my device again?

        Reply
  3. Mines didn’t work I used Kubuntu in a vm I don’t know what is happening. First, I tried installing it without removing it and it didn’t work. Second, i removed it then it says it is installed but then I checked using ls -l /usr/src/linux-headers-$(uname -r) and it still says it is not installed. so help me, I’m using the latest version of Kubuntu

    Reply
  4. Dave Mitchell February 7, 2020, at 9:38 am.

    This did not work for me. when i ran sudo apt install linux-headers-$(uname -r), all i got was E: Unable to locate package linux-headers-4.4.196-16940-geab5e6346fdb

    E: Couldn’t find any package by glob ‘linux-headers-4.4.196-16940-geab5e6346fdb’
    E: Couldn’t find any package by regex ‘linux-headers-4.4.196-16940-geab5e6346fdb’

    I’m also having a similar problem trying to install Linux headers 4.5.0.

    Okay, I was trying to install RTL8821CE driver for my wireless network adapter to work but instead, an error message appears when I try to install it using dkms-install saying that “couldn’t locate Linux-headers…

    And it’s really giving me a headache.

    Reply
  5. Any difference in using:

    # ls -l /usr/src/linux-headers-$(uname -r)
    

    And

    # ls -l /usr/src/linux-headers-$[uname -r]
    
    Reply
    • @Joprin

      Yes, there is a difference, which is bash does not support $[command]. You will get a syntax error.

      Reply
  6. I am cross-compiling the kernel for arm board on my laptop. I want a kernel header for the arm Linux before the cross-compiling the Linux for an arm. Can you suggest to me how it possible?

    Reply
  7. This did not work for me. when i ran sudo apt install linux-headers-$(uname -r), all i got was E: Unable to locate package linux-headers-4.4.196-16940-geab5e6346fdb

    E: Couldn’t find any package by glob ‘linux-headers-4.4.196-16940-geab5e6346fdb’
    E: Couldn’t find any package by regex ‘linux-headers-4.4.196-16940-geab5e6346fdb’

    Reply
    • @Dave,

      May I know on which version of Linux distribution you are trying to run? I have just checked the command on my Ubuntu 18.04 and Linux Mint 19, the command worked for me..

      Reply

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.