Sometimes you run into a shortcoming in your Linux distribution and you find that a package you want doesn't exist. Perhaps there are is no package for the software available (for example, there is no rubygem-cucumber-nagios package available for CentOS 5). Perhaps the package available is too old (for example, there is no official PHP 5.3.x package for CentOS 5). Perhaps you need functionality built into the package that isn't normally there (for example, patching Apache httpd for mpm-itk). In these cases, you either need to find a package someone else has made or roll your own.
Before you think about installing directly from source, stop. This is a bad habit to get into. It will not scale.
Red Hat Enterprise Linux, Fedora Linux, SuSE, and their derivatives use RPMs for packaging. In this, I hope to show you how to build RPMs from source RPMs. In the future, I hope to show how to add patches to source RPMs to build customized packages.
(You may be able to follow these instructions to build your own RPMs from source. To do this, you will need to skip the step of "installing" the source RPM and will instead need to write your own spec file. I don't have any personal experience with this so I can't help you.)
Before you start anything, make sure you're not doing this as root. If you build RPMs as root, you run a risk of files ending up in system paths rather than in the RPM build path.
Doing it as a normal user? Good. Set up your build environment:
-
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
-
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
(For more information, you may want to read the CentOS documentation on setting up the RPM build environment.)
On CentOS and other RHEL derivatives, you will need to install the rpm-build
and redhat-rpm-config
packages. On other distributions, you may need to install other packages.
Once you have your build directory set up, install your chosen source RPM:
-
rpm -i rubygem-gem2rpm-0.6.0-1.el5.src.rpm
This will install the source files in ~/rpmbuild/SOURCES
and the spec file in ~/rpmbuild/SPECS
.
To build the RPM, you can simply run:
-
rpmbuild -ba ~/rpmbuild/SPECS/rubygem-gem2rpm.spec
This will put the binary RPM under in architecture-dependent directory under ~/rpmbuild/RPMS/
. For example, the RPM built for rubygem-gem2rpm is architecture dependent and rubygem-gem2rpm-0.6.0-1.noarch.rpm
will be placed under ~/rpmbuild/RPMS/noarch/
.
From here, you could simply install the rpm with sudo rpm -i ~/rpmbuild/RPMS/noarch/rubygem-gem2rpm-0.6.0-1.noarch.rpm
. I don't recommend this approach. Instead, I recommend signing the RPMs and adding them to a central yum repository. I will cover both of these in the future so stay tuned.
Add new comment