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)
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)
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)
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)
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.
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?
Do you have access to cd rom?
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.
@Devlabs,
To install Linux Headers on Debian, use the following commands…
I am offline installing packages on Ubuntu.
@Devlabs,
Then you should try apt-offline tool, which is an offline package management functionality for Debian-based systems.
I made my Debian not work when I pasted in
#
reboot. It got stuck, so I pressedx
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?
Oh, sorry about that. I had to restart my device.
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 KubuntuDidn’t work for me either, Debian 10.0 it’s bitching about kbuild even tho I installed kbuild.
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-geab5e6346fdbE: 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.
I had the same problem (Ubuntu 18.04 running on Windows10), finally found out that the origin of the problem was my wsl version, it was wsl1 when it should have been wsl2. As soon as I upgraded it everything started working.
Here is the guide for upgrading wsl1 to wsl2 using PowerShell (step-2):
https://docs.microsoft.com/en-us/windows/wsl/install-win10#step-4—download-the-linux-kernel-update-package
Any difference in using:
And
@Joprin
Yes, there is a difference, which is bash does not support $[command]. You will get a syntax error.
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?
This doesn’t work for me either running Debian 10.0.
@TJ
We will cross-check this. Thanks for the feedback.
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-geab5e6346fdbE: 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’
@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..