YUM Download Source RPM

How do I yum install SRPM from CentOS/Red Hat site, instead of manually download the srpm from one of the ftp website?

Install yum-utils

# yum install yum-utils

yum-utils is a collection of utilities and examples for the yum package manager. It includes utilities by different authors that make yum easier and more powerful to use. These tools include: debuginfo-install, package-cleanup, repoclosure, repodiff, repo-graph, repomanage, repoquery, repo-rss, reposync, repotrack, verifytree, yum-builddep, yum-complete-transaction, yumdownloader, yum-debug-dump and yum-groups-manager.

Create srpm repos

After installing yum-utils, now create a repos for srpm.

# vi /etc/yum.repos.d/srpm.repo

If you use CentOS, the content of this file would be something like this:

[centos-src]
name=CentOS $releasever - $basearch - Source
baseurl=http://mirror.centos.org/centos/$releasever/os/SRPMS/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

If you use Red Hat, then the content of  this file would be something like this:

[rhel-src]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/SRPMS/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
 

Save and close the file, and then do a yum update:

# yum update

In the output of this command, you should see your new repos has been added.

How to download an SRPM

$ yumdownloader --source <package-name>

For instance, we'll download httpd srpm:

$ yumdownloader --source httpd
Loaded plugins: fastestmirror
centos-src                                               |  951 B     00:00    
centos-src                                                     1186/1186
......
httpd-2.2.3-22.el5.centos.src.rpm       | 6.2 MB     00:51

Now you can install the rpm:

# rpm -Uvh httpd-2.2.3-22.el5.centos.src.rpm

This will install the extracted files in /usr/src/redhat.

Use Mock

Now in Red Hat or CentOS 5.3, when you install an src.rpm, you get warning messages like:

# rpm -Uhv httpd-2.2.3-22.el5.centos.src.rpm
   1:httpd                 
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root

Here is an article showing how to use mock. I tried mock. I think the concept is very good, but it is still in early development.