When you are compiling a device driver module, you need to install the kernel header file in the system. The kernel header file is also required when you compile user space programs directly linked to the kernel. When you install the kernel header file in these cases, you must ensure that the kernel header file exactly matches your current kernel version (e.g. 3.13.0-24-generic).
If your kernel is the kernel version that comes with the distribution, or you use the basic warehouse of the default package manager to upgrade (such as apt GER, aptitude or Yum), you can also use the package manager to install the kernel header file. On the other hand, if you download the kernel source code and compile it manually, you can use the make command to install the matching kernel header file.
Now let’s assume that your kernel comes with the distribution. Let’s see how to install the matching header file.
Install kernel header files on Debian, Ubuntu, or Linux MINT
Assuming you don’t compile the kernel manually, you can use the apt get command to install the matching kernel header file.
First, use the dpkg query command to check whether a kernel header file is available.
The code is as follows:
<p> dpkg-query: package ‘linux-headers-3.11.0-26-generic’ is not installed and no information is available
Then use the following command to install the matching kernel header file.
The code is as follows:
Verify that the header file was successfully installed.
The code is as follows:
<p> Package: linux-headers-3.11.0-26-generic
Status: install ok installed
Debian, Ubuntu and Linux Mint default header files are under / usr / SRC.
Install kernel header files on Fedora, CentOS, or RHEL
Assuming you don’t compile the kernel manually, you can use the yum command to install the matching kernel header file.
First, check whether the system has installed the header file with the following command. If the following command has no output, it means that there is no header file yet.
The code is as follows:
Then use the yum command to install the header file. This command will automatically find the appropriate header file and install it.
The code is as follows:
Verify the status of the package installation.
The code is as follows:
<p> kernel-headers-3.10.0-123.9.3.el7.x86_64