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 ftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/kernel-2.6.18-8.1.8.el5.src.rpm
# 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.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop










![RHEL / CentOS Yum Command: Blacklist Packages [ Disable Certain Packages ]](http://s13.cyberciti.org/images/shared/rp/3/3.jpg)



{ 7 comments… read them below or add one }
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…
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 http://kbase.redhat.com/faq/FAQ_85_5109.shtm
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.
hi,
i want the source code of Linux.
i don’t know exact location for it.
could i know about this?
thank you.
I want source code of LinuxKernel and Redhat linux
I think you have a typo in your example.
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.
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 :)
In RHEL 6, at least, you can simply: