Installing Kernel Headers on AlmaLinux 9 or Rocky Linux 9

Kernel headers are packages that are essential for building and installing third-party kernel modules or device drivers because they provide definitions of structures, constants, and function prototypes. That’s why Kernel headers, are also known as Kernel development packages. It contains important header files and development libraries required for compiling and linking modules against the Linux kernel. In simple words, headers allow user applications to interact with the system kernel.

Importance of Kernel Headers:

  1. Kernel headers are quite important and needed for compiling kernel modules.
  2. For developing a device driver so that hardware works properly, developers need kernel headers to access kernel functionality and implement driver features.
  3. They also define the Application Programming Interface (API) of the Linux kernel.
  4. A program installer may require access to the appropriate kernel headers while installing a third-party kernel module or device driver on a Linux system.
  5. In some cases, kernel headers are used when patching or modifying the Linux kernel.
  6. In the development of the Linux kernel itself, headers play an important role because they act as references to developers while writing or modifying kernel code.

Step 1: Update Alamlinux or Rocky Packages

Jump to your Linux command terminal and start executing the system update command before installing the Kernel headers. The command will update the system packages and repositories as well.

sudo yum update

Step 2: Identify the Installed Kernel Version

The second step is to know what version of kernel is currently installed on our Almalinux or Rocky so that you can install the same version kernel header. For this, you can run the given command:

uname -r

Copy the kernel version because we are going to use it in the next step.

Step 3: Install Kernel Headers

In the previous step, we have identified the Linux kernel version running on our system, now we can use that to install the Kernel headers package available corresponding to that.

Here is the command syntax, we can use:

sudo yum install kernel-devel-<kernel_version>

Replace the <kernel_version> with the exact version displayed in the previous step. However, to make things easy we can let the system automatically select and install it using the given command:

sudo dnf install kernel-devel-$(uname -r)

This command will automatically identify the latest version of the kernel installed on our Almalinux and configure the corresponding kernel headers.

install kernel devel header Almalinux or Rocky Linux

The above command will also install the other development packages such as bison, limpmc, GCC, make, openssl-devel etc. required for building modules. Nevertheless, if you only want the Kernel headers then instead of using the previous command use this one:

sudo dnf install kernel-headers-$(uname -r)
Install only kernel header

Step 4: Verify Installation

To confirm we have done the installation of Kernel headers successfully, we use the given command that will check the presence of Header files on our Almalinux or Rocky inside “/usr/include/linux” directory.

ls /usr/include/linux

You will see the list of headers files after executing the above command, meaning the installation is successfully done and now we can start working on your project or program.

Verify Installation of kernel headers

Other Articles:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.