When you compile a device driver a custom kernel module, you need to have kernel header files installed on your Linux system. Kernel headers are needed also when you build a userspace application which links directly against the kernel. When you install kernel headers in such cases, you must make sure to kernel headers are exactly matched with the kernel version of your system (e.g., 3.13.0-24-generic).
If your kernel is the default version that comes with the distribution, or you upgraded it using the default package manager (e.g., apt-get, aptitude or yum) from base repositories, you can install matching kernel headers using the package manager as well. On the other hand, if you downloaded the kernel source and compiled it manually, you can install matching kernel headers by using make command.
Here we assume that your kernel comes from base repositories of your Linux distribution, and see how we can install matching kernel headers.
Install Kernel Headers on Debian, Ubuntu or Linux Mint
Assuming that you did not manually compile the kernel, you can install matching kernel headers using apt-get command.
First, check if matching kernel headers are already available on your system using dpkg-query command.
dpkg-query: package 'linux-headers-3.11.0-26-generic' is not installed and no information is available
Go ahead and install matching kernel headers as follows.
Verify that matching kernel headers are successfully installed.
Package: linux-headers-3.11.0-26-generic Status: install ok installed
The default location of kernel headers on Debian, Ubuntu or Linux Mint is /usr/src.
Install Kernel Headers on Fedora, CentOS or RHEL
If you did not manually upgrade the kernel, you can install matching kernel headers using yum command.
First, check if matching kernel headers are already installed on your system. The default location of kernel header files is /usr/src/kernels/.
If no matching kernel headers are found in that directory, go ahead and install kernel headers with yum command as follows.
If the kernel header files installed by the above command do not match with your current kernel, this is because your kernel is outdated. In this case, update the installed kernel to the latest by running the following command. This will install the matching kernel automatically. You will need to reboot after updating the kernel.
Now verify that matching kernel headers are installed by running:
arch firmware ipc Makefile samples System.map vmlinux.id block fs Kconfig mm scripts tools crypto include kernel Module.symvers security usr drivers init lib net sound virt
Subscribe to Ask Xmodulo
Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!