6.5. Building RPMs
You can build RPM packages by using the rpmbuild command. When using this command, a certain directory and file structure is expected, which is the same as the structure that was set up by the rpmdev-setuptree utility.
Different use cases and desired outcomes require different combinations of arguments to the rpmbuild command. The following are the main use cases:
- Building source RPMs.
Building binary RPMs:
- Rebuilding a binary RPM from a source RPM.
-
Building a binary RPM from the
specfile.
6.5.1. Building a source RPM リンクのコピーリンクがクリップボードにコピーされました!
Building a Source RPM (SRPM) has the following advantages:
-
You can preserve the exact source of a certain
Name-Version-Releaseof an RPM file that was deployed to an environment. This includes the exactspecfile, the source code, and all relevant patches. This is useful for tracking and debugging purposes. - You can build a binary RPM on a different hardware platform or architecture.
Prerequisites
You have installed the
rpmbuildutility on your system:# dnf install rpm-buildThe following
Hello World!implementations were placed into the~/rpmbuild/SOURCES/directory:-
A
specfile for the program that you want to package exists.
Procedure
Navigate to the
~/rpmbuild/SPECS/directive, which contains the createdspecfile:$ cd ~/rpmbuild/SPECS/Build the source RPM by entering the
rpmbuildcommand with the specifiedspecfile:$ rpmbuild -bs <specfile>The
-bsoption stands for the build source.For example, to build source RPMs for the
bello,pello, andcelloprograms, enter:$ rpmbuild -bs bello.spec Wrote: /home/admiller/rpmbuild/SRPMS/bello-0.1-1.el8.src.rpm $ rpmbuild -bs pello.spec Wrote: /home/admiller/rpmbuild/SRPMS/pello-0.1.2-1.el8.src.rpm $ rpmbuild -bs cello.spec Wrote: /home/admiller/rpmbuild/SRPMS/cello-1.0-1.el8.src.rpm
Verification
-
Verify that the
rpmbuild/SRPMSdirectory includes the resulting source RPMs. The directory is a part of the structure expected byrpmbuild.
6.5.2. Rebuilding a binary RPM from a source RPM リンクのコピーリンクがクリップボードにコピーされました!
To rebuild a binary RPM from a source RPM (SRPM), use the rpmbuild command with the --rebuild option.
The output generated when creating the binary RPM is verbose, which is helpful for debugging. The output varies for different examples and corresponds to their spec files.
The resulting binary RPMs are located in either of the following directories:
-
~/rpmbuild/RPMS/YOURARCH, whereYOURARCHis your architecture. -
~/rpmbuild/RPMS/noarch/, if the package is not architecture-specific.
Prerequisites
You have installed the
rpmbuildutility on your system:# dnf install rpm-build
Procedure
Navigate to the
~/rpmbuild/SRPMS/directive, which contains the SRPM:$ cd ~/rpmbuild/SRPMS/Rebuild the binary RPM from the SRPM:
$ rpmbuild --rebuild <srpm>For example, to rebuild
bello,pello, andcellofrom their SRPMs, enter:$ rpmbuild --rebuild bello-0.1-1.el8.src.rpm [output truncated] $ rpmbuild --rebuild pello-0.1.2-1.el8.src.rpm [output truncated] $ rpmbuild --rebuild cello-1.0-1.el8.src.rpm [output truncated]
Invoking rpmbuild --rebuild involves the following processes:
-
Installing the contents of the SRPM (the
specfile and the source code) into the~/rpmbuild/directory. - Building an RPM by using the installed contents.
-
Removing the
specfile and the source code.
You can retain the spec file and the source code after building either of the following ways:
-
When building the RPM, use the
rpmbuildcommand with the--recompileoption instead of the--rebuildoption. Install SRPMs for
bello,pello, andcello:$ rpm -Uvh ~/rpmbuild/SRPMS/bello-0.1-1.el8.src.rpm Updating / installing… 1:bello-0.1-1.el8 [100%] $ rpm -Uvh ~/rpmbuild/SRPMS/pello-0.1.2-1.el8.src.rpm Updating / installing… …1:pello-0.1.2-1.el8 [100%] $ rpm -Uvh ~/rpmbuild/SRPMS/cello-1.0-1.el8.src.rpm Updating / installing… …1:cello-1.0-1.el8 [100%]
6.5.3. Building a binary RPM from a spec file リンクのコピーリンクがクリップボードにコピーされました!
To build a binary RPM from its spec file, use the rpmbuild command with the -bb option.
Prerequisites
You have installed the
rpmbuildutility on your system:# dnf install rpm-build
Procedure
Navigate to the
~/rpmbuild/SPECS/directive, which containsspecfiles:$ cd ~/rpmbuild/SPECS/Build the binary RPM from its
spec:$ rpmbuild -bb <spec_file>For example, to build
bello,pello, andcellobinary RPMs from theirspecfiles, enter:$ rpmbuild -bb bello.spec $ rpmbuild -bb pello.spec $ rpmbuild -bb cello.spec