How to unpack, modify, rebuild and install a SRPM

https://unix.stackexchange.com/questions/16904/how-to-unpack-modify-rebuild-and-install-a-srpm

Asked 14 years, 6 months ago Modified 8 years, 9 months ago Viewed 26k times 12

I would like to modify a Fedora 15 package (gnome-shell-extensions-alternative-status-menu). It’s a small modification (reverting this commit). Using yumdownloader I’m able to download a SRPM (gnome-shell-extensions-3.0.2-1.g63dd27cgit.fc15.src.rpm).

After this, how do I unpack it and then rebuild it?

fedorarpm Share Improve this question Follow edited Jul 18, 2011 at 22:01 asked Jul 18, 2011 at 19:00 Vitor Py’s user avatar Vitor Py 1,93222 gold badges1919 silver badges2626 bronze badges You should change your recent edit to either be comments on @mdpc’s answer or add an answer of your own with the steps that helped you solve the problem. Keep answer data out of the question itself please. – Caleb CommentedJul 18, 2011 at 21:52 @Caleb Done! (3 more to go…) – Vitor Py CommentedJul 18, 2011 at 22:03 Add a comment 2 Answers Sorted by:

Highest score (default) 14

What I do, as the ROOT user:

Install the SRPM as you would any other package (rpm –install [source-rpm-filename])

Examine /root/rpmbuild/SPECS directory and find the specs file that matches your package

rpmbuild -bb /root/rpmbuild/SPECS/[found-filename]

The resulting binary packages are then located in the /root/rpmbuild/RPMS/ directory which are ready to be installed via the standard rpm –install command.

NOTE: This just builds what is in the standard binary package. I am posting this answering the specific question, not how to go about making changes to the source and generating new packages.

To do the modifications, you could either provide patches as input and changing the SPECS file….or you could replace the standard *.tar.bz2 located in /root/rpmbuild/SOURCES with your own with the change and then do the build as described above.

Beware you might have to change the SPECS package to make it work (usually by pulling out the patching, and changing some filenames that is programmed by the SPECS file).

EDIT It seems building rpms as root is a bad practice (source). It works fine as a non-root user.

Step by step instructions to add a patch (from here):

Copy your patch to rpmbuild/SOURCES. Edit the rpmbuild/SPECS/package.spec and add a Patch0: mypatch.patch right after the Source0: … line. After the %setup … line add a %patch0 -p1 line Now it will build normally, ie. with: rpmbuild -ba SPECS/package.spec

Share Improve this answer Follow edited Apr 20, 2017 at 3:50 slm’s user avatar slm♦ 380k127127 gold badges794794 silver badges897897 bronze badges answered Jul 18, 2011 at 19:19 mdpc’s user avatar mdpc 7,02155 gold badges3636 silver badges4646 bronze badges 2 You should clarify that only the install is done as root, not the rpmbuild. Building rpm files should never be done as root. – Caleb CommentedJul 18, 2011 at 21:51 @Caleb I installed as non root the packages. rpm puts it in ~/rpmbuild hierarchy. Also I did as you suggested on the question and put the extra steps here. – Vitor Py CommentedJul 18, 2011 at 22:03 Just a couple notes: sudo dnf install rpmdevtools is needed for rpmbuild command. And the %patch0 -p1 line should be omitted if the spec file uses a %autosetup line instead of a %setup one (as %autosetup applies the patch automatically). – Nelson CommentedMar 3, 2019 at 5:25 Also, to install the new rpm over the original one (in case the original is already installed on the system), do sudo rpm -ivh –force your.rpm – Nelson CommentedMar 3, 2019 at 5:58 rpm-ivh over an existing binary package is a terrible idea. – user2066657 CommentedDec 15, 2022 at 15:30 Add a comment 4

OpenSSL Package Rebuild CentOS 6.4 is a detailed example of an SRPM package rebuild.

The above example uses Mock - the Jedi Light Saber of package builders.

Mock was created to reliably populate a chroot, then rebuild a package in that chroot.

For more, see http://fedoraproject.org/wiki/Projects/Mock

In the example mock is used 3 times - once to “unpack” the package, then to rebuild the .src.rpm, and finally to create the .rpm.

Share Improve this answer Follow edited Apr 13, 2017 at 12:36 Community’s user avatar CommunityBot 1 answered Jul 4, 2013 at 18:46 neonzeon’s user avatar neonzeon 40022 silver badges9

Updated: