Redhat enterprise Linux / CentOS installing kernel source code

by on August 15, 2007 · 7 comments· LAST UPDATED August 20, 2007

in , ,

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.

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 7 comments… read them below or add one }

1 John September 24, 2007 at 8:44 pm

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…


2 John September 24, 2007 at 10:07 pm

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.


3 Shraddha January 17, 2009 at 3:53 pm

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


4 Noufal February 14, 2009 at 2:14 pm

I want source code of LinuxKernel and Redhat linux


5 Rob May 13, 2009 at 4:35 pm

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.


6 anybody June 25, 2009 at 7:39 am

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 :)


7 Nathan Kidd March 28, 2013 at 3:18 pm

In RHEL 6, at least, you can simply:

yum install --enablerepo rhel-debuginfo kernel-debuginfo


Leave a Comment

Tagged as: , , , , , , , , , , , ,

Previous Faq:

Next Faq: