install kernel headers on rhel centos

How to Install Kernel Headers in RHEL & CentOS

When you compile device drivers and certain modules, they require support of kernel headers, which are basically C files containing functions and structures to interface easily with the Linux kernel. Kernel headers are required to install and compile any code that interfaces with the kernel. While installing kernel headers, it is important to ensure that the kernel headers version matches that of kernel. In this article, we will learn how to install kernel headers in RHEL & CentOS Linux systems. While installing kernel headers, you need to follow the same approach that was used to upgrade or install the underlying kernel. That is, if the kernel was upgraded using package manager, you need to install kernel headers using package managers. If it is was installed by compiling from source, you need to install kernel headers by compiling from source.


How to Install Kernel Headers in RHEL & CentOS

Here are the steps to install Kernel headers in RHEL & CentOS. In RHEL & CentOS systems, kernel headers are located at /usr/src/kernels/ location. You can verify it with the following command.

# cd /usr/src/kernels/
# ls -l

If the above command displays matching kernel headers, you don’t need to proceed further and install them again. Otherwise, run the following command to install kernel headers using kernel-devel package.

# yum install kernel-devel   [On CentOS/RHEL 7]
# dnf install kernel-devel   [On Fedora 22+]

You will see installation progress as displayed above. Once the kernel headers are installed, you can verify them by checking the content of /usr/src/kernels directory.

# ls -l /usr/src/kernels/$(uname -r) 

The above commands may not install kernel header files used by libraries like glibc. For this purpose, you need to install kernel-header package.

# yum install kernel-headers   [On CentOS/RHEL 7]
# dnf install kernel-headers   [On Fedora 22+]

Once you have installed the correct kernel headers, you can use them to compile kernel modules and device drivers as per your requirement. Kernel headers are part of kernel and are generally installed or upgraded along with kernel headers. So in most cases, you may not need to explicitly install kernel headers on your system. However, if it has been corrupted or accidentally deleted, then you can follow the above steps to install kernel headers separately.

Although kernel headers are part of kernel, they are distributed separately so that the changes in kernel headers don’t affect underlying kernel and also to make it easy for device drivers & modules to easily interface with the kernel.

Couple of key things to remember is to install the kernel header version that matches your kernel’s version, and also use the same approach that was used to install or upgrade the kernel. If you had used package manager to upgrade/install kernel, then use package manager to install kernel header. If you had compiled kernel from source, you need to compile kernel-header from source. You can use the above mentioned installation steps in RHEL, CentOS, Fedora & SUSE Linux systems.

Also read:

How to Install Kernel Headers in Ubuntu/Debian
How to Migrate from GitHub to BitBucket
How to Transfer All MySQL Databases form One Server to Another
How to List All Virtual Hosts in NGINX
How to Remove Docker Images, Containers & Volumes

Leave a Reply

Your email address will not be published. Required fields are marked *