How To: Install Kernel Source Code in CentOS/RedHat
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:
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:
That’s quite a bit of source codes:
Official Linux Kernel website: Kernel.org
Red Hat Linux