- How to install kernel headers on Linux
- Install Kernel Headers on Debian, Ubuntu or Linux Mint
- Install Kernel Headers on Fedora, CentOS or RHEL
- Support Xmodulo
- How to Install Kernel Headers in CentOS 7
- Install Kernel Headers in CentOS 7
- How To: Install Kernel Source Code in CentOS/RedHat
- Install Kernel Sources and Headers in RedHat/CentOS
- Why Kernel Source is Old Version in Your OS
- See Also
How to install kernel headers on Linux
Question: I need to install kernel headers to install a device driver for my kernel. What is a proper way to install matching kernel headers on [insert your Linux distro]?
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 -s linux-headers-$(uname -r)
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.
$ sudo apt-get install linux-headers-$(uname -r)
Verify that matching kernel headers are successfully installed.
$ dpkg-query -s linux-headers-$(uname -r)
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.
$ sudo yum install kernel-devel
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
Support Xmodulo
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
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.
How To: Install Kernel Source Code in CentOS/RedHat
CentOS Linux From time to time it’s required to compile some Linux kernel specific software on your CentOS/RedHat Linux system. Most often it’s some kind of kernel module specific to a software that requires deep integration with your operating system.
Install Kernel Sources and Headers in RedHat/CentOS
You need to install two packages: kernel sources from kernel-develop and header files from kernel-headers:
[email protected]:~ # yum install kernel-devel kernel-headers Loaded plugins: fastestmirror, langpacks Determining fastest mirrors epel/x86_64/metalink | 28 kB 00:00:00 - base: centos.quelquesmots.fr - epel: mirror.in2p3.fr - extras: centos.crazyfrogs.org - updates: centos.quelquesmots.fr base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/4): epel/x86_64/updateinfo | 998 kB 00:00:00 (2/4): extras/7/x86_64/primary_db | 201 kB 00:00:00 (3/4): updates/7/x86_64/primary_db | 5.0 MB 00:00:00 (4/4): epel/x86_64/primary_db | 6.7 MB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package kernel-devel.x86_64 0:3.10.0-957.12.2.el7 will be installed ---> Package kernel-headers.x86_64 0:3.10.0-957.12.2.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================ Package Arch Version Repository Size ============================================================================ Installing: kernel-devel x86_64 3.10.0-957.12.2.el7 updates 17 M kernel-headers x86_64 3.10.0-957.12.2.el7 updates 8.0 M # Transaction Summary Install 2 Packages Total download size: 25 M Installed size: 41 M Is this ok [y/d/N]: y Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/2): kernel-headers-3.10.0-957.12.2.el7.x86_64.rpm | 8.0 MB 00:00:00 (2/2): kernel-devel-3.10.0-957.12.2.el7.x86_64.rpm | 17 MB 00:00:00 --- Total 55 MB/s | 25 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : kernel-devel-3.10.0-957.12.2.el7.x86_64 1/2 Installing : kernel-headers-3.10.0-957.12.2.el7.x86_64 2/2 Verifying : kernel-headers-3.10.0-957.12.2.el7.x86_64 1/2 Verifying : kernel-devel-3.10.0-957.12.2.el7.x86_64 2/2 Installed: kernel-devel.x86_64 0:3.10.0-957.12.2.el7 kernel-headers.x86_64 0:3.10.0-957.12.2.el7
Complete! I just realised that the same packages will most obviously be needed if you ever decide to compile your Linux kernel.
Why Kernel Source is Old Version in Your OS
Most Linux distros lag quite a big behing the latest Linux kernel version: this is expected, because their maintainers need time to download and complile the latest kernel and to also complete the full suite of integratory tests. This is done so that most of key software running in a particular distro will still function. Quite possibly, lots of kernel modules specific to a distro are re-compiled at that stage. What this means is that your Linux distro will not have the latest branch of Kernel sources (5.1 as of May 2019). In this example today, my CentOS 7.6 system is using and downloading Linux Kernel 3.10.0. Verify If You Have Kernel Sources Installed Simply look in the /usr/src/kernels directory: you will at least have the just-installed packages but quite possibly older versions as well:
[email protected]:~ # ls /usr/src/kernels/ 3.10.0-957.12.2.el7.x86_64 [email protected]:~ # ls /usr/src/kernels/3.10.0-957.12.2.el7.x86_64/ arch drivers include Kconfig Makefile Module.symvers scripts System.map virt block firmware init kernel Makefile.qlock net security tools vmlinux.id crypto fs ipc lib mm samples sound usr
[email protected]:~ # du -sh /usr/src/kernels/3.10.0-957.12.2.el7.x86_64 74M /usr/src/kernels/3.10.0-957.12.2.el7.x86_64