CentOS7 build environment (src.rpm -> rpm)

One of the things I hate the most about CentOS is the fact that once they release a new version they seem to also lock major versions of various packages with it like for example php or mysql which seem frozen in time, not to mention the kernel. My solution usually is to simply use some other repos (other than the official ones) like epel, remi, etc to install newer versions of various software BUT sometimes these are useless (like for example if you want to install latest available version of squid or haproxy OR for example when we had the latest exim CVE and they took their sweet time to release the patched version …).

I for one am a man of action … if I need something fixed NOW and I can do something about it … I will, if I need to use a newer version of something and there is no binary package for my Linux distro I’ll compile it.

Here’s how one can build rpm packages on CentOS7 (should you need to do this for whatever reason):

yum install rpm-build
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
yum groupinstall "Development Tools"
yum install ncurses-devel

And you’re good to go! 🙂
The commands above installed the necessary tools that will compile packages for you and have prepared the rpmbuild environment in your home directory. The last package I usually install because I tend to compile my kernel as well and the process uses the ncurses libraries to generate the “fancy” interface that allows you to enable/disable modules/drivers/etc in your kernel config.

If you want to test that everything works okay simply get any official src.rpm package (ex. http://vault.centos.org/7.7.1908/os/Source/SPackages/haproxy-1.5.18-9.el7.src.rpm), open the archive and you’ll find a cpio file there. Open that and it will contain various other files. Copy the spec file into the rpmbuild/SPEC and the other files into the rpmbuild/SOURCES then go to the SPEC folder and run:
rpmbuild -ba haproxy.spec

This should compile the src.rpm and give you a proper rpm in rpmbuild/RPMS/ under the correct arch subdir

Go crazy and compile some new shit on CentOS7! 🙂

PS. Here’s some of the stuff I played with:

rpm -qa kernel
kernel-4.19.81-1.x86_64

rpm -qa haproxy
haproxy-2.1.4-1.el7.x86_64


Posted

in

by