Linux installation of the appropriate kernel header file method

  

Linux system operation, sometimes need to install the kernel header file when installing the device driver, and many friends do not know what is the kernel header file, naturally do not know how to install, the following small I will introduce you to the method of installing kernel header files in Linux.

Question: I need to install the kernel header file before installing a device driver. How to install the appropriate kernel header file?

When you are compiling a device driver module, you need to install the kernel header file on your system. Kernel header files are also needed when you compile userspace programs that are directly linked to the kernel. When you install kernel headers in these situations, you must ensure that the kernel headers match exactly your current kernel version (eg 3.13.0-24-generic).

If your kernel is release comes with the kernel version, or use the default base warehouse package manager to upgrade (for example: apt-ger, aptitude or yum), you can also use The package manager installs the kernel header files. On the other hand, if you downloaded the kernel source and compiled it manually, you can use the make command to install the matching kernel headers.

Now let's assume that your kernel is included with the distribution. Let's see how to install matching header files.

Installing Kernel Header Files on Debian, Ubuntu, or Linux Mint

Assuming you didn't compile the kernel manually, you can use the apt-get command to install matching kernel header files.

First, use the dpkg-query command to check if there are kernel header files available.

$ dpkg-query -s linux-headers-$(uname -r)

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.

$ sudo apt-get install linux-headers - $ (uname -r)

Authentication Header files are successfully installed.

$ dpkg-query -s linux-headers-$(uname -r)

Package: linux-headers-3.11.0-26-generic

Status: install Ok installed

Debian, Ubuntu, Linux Mint default header files are under /usr/src.

Installing Kernel Header Files on Fedora, CentOS, or RHEL

Assuming you didn't manually compile the kernel, you can use the yum command to install matching kernel header files.

First, use the following command to check if the system has installed the header file. If the following command does not have any output, this means that there is no header file yet.

$ rpm -qa |  Grep kernel-headers-$(uname -r)

Then use the yum command to install the header files. This command will automatically find the appropriate header file and install it.

$ sudo yum install kernel-headers

verify the status of the installation package.

$ rpm -qa |  Grep kernel-headers-$(uname -r)

kernel-headers-3.10.0-123.9.3.el7.x86_64

Location of default kernel header files on Fedora, CentOS or RHEL Is /usr/include/linux.

The above is the introduction of the Linux kernel header file. It should be noted that the yum command can be used to automatically find the appropriate header file when installing the kernel header file to avoid unnecessary trouble.

Copyright © Windows knowledge All Rights Reserved