How do I install kernel header files?
You should be able to install the kernel header files for the currently running kernel by running the following in a terminal:
sudo apt-get install linux-headers-$(uname -r)
In general, the kernel header packages are named linux-header-* where «*» indicates the version & variant (generic, server, etc.).
hey thanks but could you tell me what does generic, server, etc means i want to write (kernel driver)
This won’t install the headers for future updates automatically and you’ll have to re-run this command every time. Therefore, it’s recommended to install the metapackage instead, as described in another answer.
sudo apt-get install linux-headers-generic
if you are on a Desktop installation. The apt-get will solve the dependencies and install the correct version of kernel headers.
In Debian Wheezy I get the error message «Package linux-headers-generic is not available, but is referred to by another package. [. ] E: Package ‘linux-headers-generic’ has no installation candidate»
@IQAndreas the linux-headers-generic package is ubuntu specific. On Debian you should use sudo apt-get install linux-headers-$(uname -r)
I have linux-headers-generic installed on 18.04 but still don’t have the headers for the newest and current kernel version. Maybe it’s just a bug with this version, I’ve compiled kernel modules in earlier versions so I must’ve had the correct headers back then.
Case of Obsolete kernel package
This should cover another problem when: the currently running kernel is obsolete, meaning it’s not in the repository anymore neither its headers. So the best thing to do is to update the kernel to last version in the repository.
linux-generic is a meta package to keep current version of the kernel & its headers:
sudo apt-get update sudo apt-get install linux-generic
Note: Depending on your Ubuntu edition, See if you need linux-lowlatency (Ubuntu Studio), linux-signed-generic or linux-virtual .
How to Install Kernel Headers in CentOS 7
When you compile a custom kernel module such as a device driver on a CentOS system, you need to have kernel header files installed on the system, which include the C header files for the Linux kernel. Kernel header files provide different kinds of function and structure definitions required when installing or compiling any code that interfaces with the kernel.
When you install Kernel Headers, make sure it matches with the currently installed kernel version on the system. If your Kernel version comes with the default distribution installation or you have upgraded your Kernel using yum package manager from system base repositories, then you must install matching kernel headers using package manager only. If you’ve compiled Kernel from sources, you can install kernel headers from sources only.
In this article, we will explain how to install Kernel Headers in CentOS/RHEL 7 and Fedora distributions using default package manager.
Install Kernel Headers in CentOS 7
First confirm that the matching kernel headers are already installed under /usr/src/kernels/ location on your system using following commands.
If no matching kernel headers are located in the /usr/src/kernels/ directory, go ahead and install kernel headers, which is provided by the kernel-devel package that can be installed using default package manager as shown.
# yum install kernel-devel [On CentOS/RHEL 7] # dnf install kernel-devel [On Fedora 22+]
After installing the kernel-devel package, you can find all the kernel headers files in /usr/src/kernels directory using following command.
# ls -l /usr/src/kernels/$(uname -r)
Note on a VPS (for instance a Linode VPS), a kernel may have a customized version name, in such scenario, you have to identify the kernel version manually and check the installed kernel header files using following commands.
# uname -r # ls -l /usr/src/kernels/3.10.0-862.2.3.el7.x86_64
Sample Output
total 4544 drwxr-xr-x. 32 root root 4096 May 16 12:48 arch drwxr-xr-x. 3 root root 4096 May 16 12:48 block drwxr-xr-x. 4 root root 4096 May 16 12:48 crypto drwxr-xr-x. 119 root root 4096 May 16 12:48 drivers drwxr-xr-x. 2 root root 4096 May 16 12:48 firmware drwxr-xr-x. 75 root root 4096 May 16 12:48 fs drwxr-xr-x. 28 root root 4096 May 16 12:48 include drwxr-xr-x. 2 root root 4096 May 16 12:48 init drwxr-xr-x. 2 root root 4096 May 16 12:48 ipc -rw-r--r--. 1 root root 505 May 9 19:21 Kconfig drwxr-xr-x. 12 root root 4096 May 16 12:48 kernel drwxr-xr-x. 10 root root 4096 May 16 12:48 lib -rw-r--r--. 1 root root 51205 May 9 19:21 Makefile -rw-r--r--. 1 root root 2305 May 9 19:21 Makefile.qlock drwxr-xr-x. 2 root root 4096 May 16 12:48 mm -rw-r--r--. 1 root root 1093137 May 9 19:21 Module.symvers drwxr-xr-x. 60 root root 4096 May 16 12:48 net drwxr-xr-x. 14 root root 4096 May 16 12:48 samples drwxr-xr-x. 13 root root 4096 May 16 12:48 scripts drwxr-xr-x. 9 root root 4096 May 16 12:48 security drwxr-xr-x. 24 root root 4096 May 16 12:48 sound -rw-r--r--. 1 root root 3409102 May 9 19:21 System.map drwxr-xr-x. 17 root root 4096 May 16 12:48 tools drwxr-xr-x. 2 root root 4096 May 16 12:48 usr drwxr-xr-x. 4 root root 4096 May 16 12:48 virt -rw-r--r--. 1 root root 41 May 9 19:21 vmlinux.id
In addition, if you need header files for the Linux kernel for use by glibc, install the kernel-header package using following command.
# yum install kernel-headers [On CentOS/RHEL 7] # dnf install kernel-headers [On Fedora 22+]
Now you are good to go with compiling your own or existing kernel modules for software such as VirtualBox and many more.
That’s it! In this article, we have explained how to install kernel-devel and kernel-header packages in CentOS/RHEL 7 and Fedora systems. Remember that before you can compile kernel modules such as device driver on a Linux system, you should have necessary kernel header files installed. If you have queries, please use the comment form below to reach us.
Chapter 3. Debian kernel packages
The linux source package supports building of kernel images and headers for all currently supported architectures. The linux-latest source package supports building of meta-packages that depend on them. The linux-signed source package supports building of signed kernel images and modules for some architectures. Subsequent sections of this chapter document the naming and contents of the binary packages built from these source packages.
3.2. Architecture-independent packages
This package contains the Debian kernel source tarball. The patchlevel of the source is determined by the Debian revision of the package, for example the version 4.2.5-1 of the package linux-source-4.2 contains the version 4.2.5 of the Debian kernel source patched to patchlevel 1. Once the package is installed, the source tarball is available at /usr/src/linux-source- version .tar.xz .
This package contains the manual pages for the functions, constituting the kernel API. These pages are installed into /usr/share/man/man9/ , and are accessible with the standard man command. Due to filename conflicts, only one linux-manual package may be installed at any given time.
This package contains the rest of the kernel documentation in various formats. It is installed in /usr/share/doc/linux-doc- version .
linux-support- version — abiname
This package contains metadata from the linux source package that is needed to prepare and build the other source packages.
linux-headers- version — abiname -common[- featureset ]
This package contains a common set of kernel headers for a particular featureset (or no featureset). Together with the flavour-specific linux-headers package it provides a full set of kernel headers, suitable for building of out-of-tree modules. This package should not normally be installed directly, but only as a dependency of the flavour-specific headers package (see below). It unpacks into the /usr/src/linux-headers- version — abiname -common[- featureset ] directory. Before version 4.9 these packages were architecture-dependent.
3.3. Architecture-dependent packages
The kind of hardware the particular kernel package is designed for is uniquely identified by the architecture , featureset , and flavour . Kernels for all architectures are built from the same Debian kernel source tree, which is obtained using the procedure described in Chapter 2, Debian kernel source. Each architecture usually has multiple flavours of the binary kernel images. Different flavours correspond to different kernel configuration files, used to build the binary images from the same kernel tree.
In order to build a working kernel with an extra featureset not provided by the upstream source, additional changes to the Debian kernel source are required. Again, multiple flavours of binary images may be built from the featureset tree. For example, the i386 architecture has a number of different flavours, such as 686 and 686-pae , built from the common Debian kernel source. It also contains the rt featureset. The source tree for building the kernels for each of these featuresets is obtained by applying additional patches to the Debian kernel source. It may be used to build the rt-686-pae binary image flavours. The names of the Debian binary packages incorporate the name of the flavour and, if necessary, the name of the featureset (there is no need to worry about the name of the architecture, since Debian tools will only allow installation of the packages with «correct» architecture). If the arch does not have any featuresets, the featureset part is omitted from the name, as indicated by the square brackets below.
Package names also include the abiname , a small integer, which identifies the kernel’s binary compatibility level. The kernels with different abinames are binary incompatible, so upgrading to a kernel with a different abiname will most likely require recompilation of third-party binary modules against the new kernel. The list of architecture-dependent packages together with a short description is given below.
This package provides flavour-specific header files. It depends on the corresponding linux-headers- version — abiname -common[- featureset ] package, and sets up symbolic links into its directory tree in such a way that the directory /usr/src/linux-headers- version — abiname [- featureset ]- flavour appears to contain a full set of headers, required for building of out-of-tree kernel modules. For more information on this check out Section 4.7, “Building out-of-tree kernel modules”. A complete set of kernel headers matching the currently running official kernel may be installed with a command
apt-get install linux-headers-$(uname -r)
These meta-packages provide (via dependencies) the latest binary image and matching set of header files (respectively) for a particular flavour. Example: linux-image-rt-686-pae
linux-image- version — abiname [- featureset ]- flavour
This package contains the binary kernel image and pre-built binary modules for a particular arch/featureset/flavour combination. Names of the files installed by this package are architecture-dependent. Typical locations of essential files for the i386 architecture are:
The binary (compressed) kernel image.
/boot/initrd.img- version — abiname [- featureset ]- flavour
Initial RAM filesystem (initramfs) image. Note, that this file is automatically generated in the installation process and is not shipped as a part of the package. See Chapter 7, Managing the initial ramfs (initramfs) archive for more details.
/boot/config- version — abiname [- featureset ]- flavour
The kernel configuration file used to build this particular kernel. May be used to rebuild the kernel from source, if necessary.
/lib/modules/ version — abiname [- featureset ]- flavour /
Directory containing the pre-built binary kernel modules.
This package contains the binary kernel image and pre-built binary modules for a particular arch/featureset/flavour combination, that are meant to be signed and copied into a package without the -unsigned suffix. There is normally no need to install these packages.
This package provides Linux kernel headers for use by userspace programs, such as GNU glibc and other system libraries.