Tutorial on installing Linux kernel header files on Linux systems

Time:2022-5-5

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.

  

Copy code

The code is as follows:

$ dpkg-query -s linux-headers-$(uname -r) </p>
<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.

   

Copy code

The code is as follows:

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

  2015614184244668.jpg (640×253)

Verify that the header file was successfully installed.

   

Copy code

The code is as follows:

$ dpkg-query -s linux-headers-$(uname -r) </p>
<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.

   

Copy code

The code is as follows:

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

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

   

Copy code

The code is as follows:

$ sudo yum install kernel-headers

    2015614184309986.jpg (640×442)

Verify the status of the package installation.

   

Copy code

The code is as follows:

$ rpm -qa | grep kernel-headers-$(uname -r) </p>
<p> kernel-headers-3.10.0-123.9.3.el7.x86_64

Recommended Today

Modify user information changeinfo

When judging the persistence layer: Problem: there is such a problem when modifying user information. For example: the user’s email is not required. It was not empty originally. At this time, the user deletes the mailbox information and submits it. At this time, if it is not empty to judge whether it needs to be […]