How to Recreate/rebuild a RPM from installed files?

Many times we encounter situations where we want to replicate one package installation on a different machine but the actual RPM file no longer available. This happens mainly when you use yum to install packages. When you try to install same package on a different machine after few months, you might not get the same version of the software from yum repos. In this article we will explain how to recreate/rebuild an RPM from installed files using rpmrebuild

Recreate/rebuild a RPM from installed files using RPMREBUILD

Rpmrebuild is a 3rd party script you can use to do a re-packaging of an already installed RPM.

Excerpts from the official page

“rpmrebuild is a tool to build an RPM file from a package that has already been installed in a basic use, rpmrebuild use does not require any rpm building knowledge. (On debian, the equivalent product is dpkg-repack).”

How to install rpmrebuild on centos ?

On a Centos machine you can install rpmrebuild using yum 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30   yum install rpmrebuild   Dependencies Resolved   ===================================================================================================================================================================================== Package Arch Version Repository Size ===================================================================================================================================================================================== Installing: rpmrebuild noarch 2.113.el6 epel 76 k   Transaction Summary ===================================================================================================================================================================================== Install 1 Package(s)   Total download size: 76 k Installed size: 181 k Is this ok [y/N]: y Downloading Packages: rpmrebuild2.113.el6.noarch.rpm | 76 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : rpmrebuild2.113.el6.noarch 1/1 Verifying : rpmrebuild2.113.el6.noarch 1/1   Installed: rpmrebuild.noarch 0:2.113.el6  

 

We have installed rpmrebuild package successfully

Creating first RPM file using rpmrebuild

First find the rpm package which we need to rebuild

1 2 3 4 5   [root@test.test.com ~]# rpm -qa |grep nginx nginx1.10.21.el6.x86_64 [root@test.test.com ~]#  

Run rpmrebuild

1 2 3 4 5 6 7 8 9 10   [root@test.test.com ~]# rpmrebuild nginx-1.10.2-1.el6.x86_64 /usr/lib/rpmrebuild/rpmrebuild.sh: WARNING: some files have been modified: S.5….T. c /etc/nginx/conf.d/default.conf S.5….T. c /etc/nginx/nginx.conf Do you want to continue ? (y/N) y Do you want to change release number ? (y/N) N result: /root/rpmbuild/RPMS/x86_64/nginx1.10.21.el6.x86_64.rpm [root@test.test.com ~]#  

From the above example, you can see that rpmrebuild created a new rpm file  and stored at “/root/rpmbuild/RPMS/x86_64/nginx-1.10.2-1.el6.x86_64.rpm” .

We can copy this to any other machine and use it to install same package on that machine.

You can find more details on their official page 

 

Author: , 0000-00-00