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.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

17 thoughts on “How to Install Kernel Headers in Ubuntu and Debian”

  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
  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
  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.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.