Redhat enterprise Linux / CentOS installing kernel source code

Q. How do I install Linux kernel source code and headers under RHEL 5 or CentOS 5 Linux operating system?

A. Both CentOS and RHEL 5 includes following packages:

a) Kernel-headers : It includes the C header files that specify the interface between the Linux kernel and userspace libraries and programs. The header files define structures and constants that are needed for building most standard programs and are also needed for rebuilding the glibc package.

b) kernel-devel : This package provides kernel headers and makefiles sufficient to build modules against the kernel package.

c) Actual kernel source code : You can always download actual source code here. Look for kernel*.rpm file.

Rhel / CentOS 5 install kernel headers

Use yum command as follows:
# yum install kernel-devel Kernel-headers

Install kernel source code

Type the command as follows:
# cd /tmp
# wget
# rpm -ivh kernel-2.6.18-8.1.8.el5.src.rpm

Note change version number as per your current kernel.

For recompiling or adding a new module or device driver you just need kernel-devel and Kernel-headers packages. To rebuilt kernel rpm goto /usr/src/redhat/SPECS directory, modify kernel spec file and use rpmbuild command to rebuild rhel/centos kernel rpm.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 8 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • John Sep 24, 2007 @ 20:44

    The various source rpm’s referenced in the article such as kernel-2.6.18-8.1.8.el5.src.rpm do not contain the source but rather patches to the source…

  • John Sep 24, 2007 @ 22:07

    Upon further examination, the *.src.rpm does have the source in a tarball within it. You’re expected to build the source tree with the rpmbuild command. A command reference would be

    Keep in mind that you will need the unifdef package which is not installed by default. You’ll find it on the third installation CD.

  • Shraddha Jan 17, 2009 @ 15:53

    i want the source code of Linux.
    i don’t know exact location for it.
    could i know about this?
    thank you.

  • Noufal Feb 14, 2009 @ 14:14

    I want source code of LinuxKernel and Redhat linux

  • Rob May 13, 2009 @ 16:35

    I think you have a typo in your example.

    # yum install kernel-devel Kernel-headers

    has a capital “K” in Kernel-headers, but that didn’t work for me. I changed it to a lowercase “k” and it worked just fine.

  • anybody Jun 25, 2009 @ 7:39

    Just look at the src.rpm for the source code. You can extract it via command

    rpm2cpio kernel-bla-bla-bla.src.rpm | cpio -idvm

    and then a simple

    ls *.tar.{bz2|gz}

    will take you to the source :)

  • Nathan Kidd Mar 28, 2013 @ 15:18

    In RHEL 6, at least, you can simply:

    yum install --enablerepo rhel-debuginfo kernel-debuginfo
  • Jerrin Jun 10, 2016 @ 16:57

    kernel-headers should be all caps:
    # yum install kernel-devel kernel-headers

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum