ERROR: Unable to find the kernel source tree for the currently running kernel – CentOS / RHEL / AlmaLinux
This article will provide you with an information on how to install kernel source on CentOS/RHEL Linux system. Alternatively it will guide you through a simple troubleshootng process in case you have already installed kernel sources/headers and yest still receiving the bellow error message:
ERROR: Unable to find the kernel source tree for the currently running kernel.  Please make sure you have installed the kernel     
         source files for your kernel and that they are properly configured; on Red Hat Linux systems, for example, be sure you have 
         the 'kernel-source' or 'kernel-devel' RPM installed.  If you know the correct kernel source files are installed, you may    
         specify the kernel source path with the '--kernel-source-path' command line option.In this tutorial you will learn:
- How to install kernel-headers
- How to install kernel-devel
- How to check kernel version
- How to check for installed kernel-devel version

ERROR: Unable to find the kernel source tree for the currently running kernel error message on CentOS / RHELSoftware Requirements and Conventions Used
| Category | Requirements, Conventions or Software Version Used | 
|---|---|
| System | Red Hat Enterprise Linux 8 / CentOS 8 | 
| Software | N/A | 
| Other | Privileged access to your Linux system as root or via the sudocommand. | 
| Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudocommand$ – requires given linux commands to be executed as a regular non-privileged user | 
How to install kernel headers and kernel devel on CentOS / RHEL step by step instructions
Step1 You can either install kernel headers and kernel devel separately or install both as part of the Development Tools package. The recommended is the installation of the entire Development Tools group package:
# dnf groupinstall "Development Tools"Alternatively install both the kernel-devel and/or kernel-headers packages separately:
# dnf install kernel-headers
# dnf install kernel-devel Step2 Check your installation and confirm that both the kernel-devel and/or kernel-headers packages match your currently loaded kernel version. Here is an example. First check your Linux kernel version:
$ uname -a
Linux sandbox 4.18.0-80.11.2.el8_0.x86_64 #1 SMP Tue Sep 24 11:32:19 UTC 2019 x86_64 x86_64 x86_64 GNU/LinuxTake a note of the kernel version and compare it with package versions of the kernel-devel and/or kernel-headers:
# rpm -qa | grep -E "kernel-devel|kernel-headers"
kernel-headers-4.18.0-80.11.2.el8_0.x86_64
kernel-devel-4.18.0-80.11.2.el8_0.x86_64If they all match your are good to go. Otherwise your system might be out of sync. See the next step for a solution.
Step3 Using the dnf command synchronise your system to make sure you are running the latest packages:
# dnf distro-syncStep4 Reboot your system and check once again that the kernel version matches the kernel-devel and/or kernel-headers package versions.
