RPM packaging: A simplified guide to creating your first RPM
How to create a Linux RPM package
RPM Packaging Guide
How to build rpm packages
What actually is $RPM_BUILD_ROOT?
├── src
│ └── source
├── build
│ └── executables, libraries, etc.
└── pkg
├── Makefile
├── myapp.spec
└── package
└── <empty>
BUILD_DIR = $(realpath .)/../build
PKG_BUILD_ROOT = $(realpath .)/package
PKG_DIR = /opt/myapp/mysubcomponent
PKG_NAME = myapp
PKG_VERSION = 1.0.0.5
PKG_RELEASE = 1
all :
rpmbuild -v -bb \
-D "BUILD_DIR $(BUILD_DIR)" \
-D "_topdir $(PKG_BUILD_ROOT)" \
-D "PKG_DIR $(PKG_DIR)" \
-D "PKG_NAME $(PKG_NAME)" \
-D "PKG_VERSION $(PKG_VERSION)" \
-D "PKG_RELEASE $(PKG_RELEASE)" \
myapp.spec
clean :
rm -rf "$(PKG_BUILD_ROOT)"
# Tags ----------------------------------------------------
Name: %{PKG_NAME}
Version: %{PKG_VERSION}
Release: %{PKG_RELEASE}
Summary: MyApp Summary
License: GPL
AutoReqProv: No
%description
MyApp Description
# Phases --------------------------------------------------
# Unpacking the sources %prep outside of packaging
# Building the software %build outside of packaging
# Installing the software in PKG_BUILD_ROOT
%install
PKG_PROTO=${RPM_BUILD_ROOT}%{PKG_DIR}
install -v -d ${PKG_PROTO}
rsync -av %{BUILD_DIR}/ ${PKG_PROTO}/
# Package the files (= include these files into the RPM package)
%files
%defattr(-,root,root,-)
%{PKG_DIR}
# Cleaning up %clean outside of packaging
# Embedded Scripts ---------------------------------------
%pre
echo "## INFO: %{PKG_NAME} : pre"
%post
echo "## INFO: %{PKG_NAME} : post"
%preun
echo "## INFO: %{PKG_NAME} : preun"
%postun
echo "## INFO: %{PKG_NAME} : postun"
$ tree package
package
├── BUILD
├── BUILDROOT
│ └── myapp-1.0.0.5-1.x86_64
│ └── opt
│ └── myapp
│ └── mysubcomponent
│ ├── bin
│ │ └── myexecutable
│ ├── etc
│ │ └── myconfig
│ └── lib
│ └── mylibrary.so
├── RPMS
│ └── x86_64
│ └── myapp-1.0.0.5-1.x86_64.rpm
├── SOURCES
├── SPECS
└── SRPMS
$ make
rpmbuild -v -bb \
-D "BUILD_DIR /home/andreas/src/myapp/build" \
-D "_topdir /home/andreas/src/myapp/pkg/package" \
-D "PKG_DIR /opt/myapp/mysubcomponent" \
-D "PKG_NAME myapp" \
-D "PKG_VERSION 1.0.0.5" \
-D "PKG_RELEASE 1" \
myapp.spec
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.AW6YVB
+ umask 022
+ cd /home/andreas/src/myapp/pkg/package/BUILD
+ '[' /home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64 '!=' / ']'
+ rm -rf /home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64
++ dirname /home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64
+ mkdir -p /home/andreas/src/myapp/pkg/package/BUILDROOT
+ mkdir /home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64
+ PKG_PROTO=/home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64/opt/myapp/mysubcomponent
+ install -v -d /home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64/opt/myapp/mysubcomponent
install: creating directory '/home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64/opt'
install: creating directory '/home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64/opt/myapp'
install: creating directory '/home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64/opt/myapp/mysubcomponent'
+ rsync -av /home/andreas/src/myapp/build/ /home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64/opt/myapp/mysubcomponent/
sending incremental file list
./
bin/
bin/myexecutable
etc/
etc/myconfig
lib/
lib/mylibrary.so
sent 14,794 bytes received 187 bytes 29,962.00 bytes/sec
total size is 14,064 speedup is 0.94
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
+ /usr/lib/rpm/redhat/brp-python-hardlink
+ /usr/lib/rpm/redhat/brp-java-repack-jars
Processing files: myapp-1.0.0.5-1.x86_64
Provides: myapp= 1.0.0.5-1. myapp(x86-64) = 1.0.0.5-1
Requires(interp): /bin/sh /bin/sh /bin/sh
Requires(rpmlib): rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1
Requires(pre): /bin/sh
Requires(post): /bin/sh
Requires(preun): /bin/sh
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/andreas/src/myapp/pkg/package/BUILDROOT/myapp-1.0.0.5-1.x86_64
Wrote: /home/andreas/src/myapp/pkg/package/RPMS/x86_64/myapp-1.0.0.5-1.x86_64.rpm
$ yum install /home/andreas/src/myapp/pkg/package/RPMS/x86_64/myapp-1.0.0.5-1.x86_64.rpm
[...]
Install 1 Package
Total size: 11 M
Installed size: 11 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
## INFO: myapp : pre
Installing : myapp-1.0.0.5-1.x86_64
## INFO: myapp : post
Verifying : myapp-1.0.0.5-1.x86_64
Installed:
myapp.x86_64 0:1.0.0.5-1
Complete!
$ yum erase myapp
[...]
Remove 1 Package
Installed size: 9.6 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
## INFO: myapp : preun
Erasing : myapp-1.0.0.5-1.x86_64
## INFO: myapp : postun
Verifying : myapp-1.0.0.5-1.x86_64
Removed:
myapp-1.0.0.5-1.x86_64
Complete!
max-rpm
Directives For the %files list
The %dir Directive
As we mentioned in the Section called The %files List, if a
directory is specified in the %files list, the contents of
that directory, and the contents of every directory under it,
will automatically be included in the package.
While this feature can be handy (assuming you are sure that
every file under the directory should be packaged) there are
times when this could be a problem.
The way to get around this, is to use the %dir directive.
Automatic Dependencies
Fedora
Packaging Tutorial: GNU Hello
Automatic Filtering of Provides and Requires
spec File
Spec file format
rsync
What actually is $RPM_BUILD_ROOT?
$RPM_BUILD_ROOT
(or the equivalent %{buildroot}
SPEC file macro) always
holds the directory under which RPM will look for any files to package.
Disable Automatic Dependency Processing
How do I prevent rpmbuild form injecting requirements into RPM package?
Disable rpmbuild automatic requirement finding (AutoReqProv: no
)
RPM Naming Schemes
Understanding RPM Versions and Naming Schemes
[name]-[version]-[release].[arch].rpm
RPM Default attributes
What does %defattr mean in RPM spec files?
The %defattr Directive
The %defattr directive allows setting of default attributes for files and directives.
The %defattr has a similar format to the %attr directive:
1. The default permissions, or "mode" for files.
2. The default user id.
3. The default group id.
4. The default permissions, or "mode" for directories.
The %attr directive has the following format:
%defattr(file mode, user, group, dir mode)
install
Baeldung: The install Command in Linux
rsync
When is -av NOT the appropriate option for rsync?
-v
verbose
-a
archive mode
includes:
-r, --recursive recurse into directories
-l, --links copy symlinks as symlinks
-p, --perms preserve permissions
-t, --times preserve modification times
-g, --group preserve group
-o, --owner preserve owner (super-user only)
-D same as --devices --specials
--devices preserve device files (super-user only)
--specials preserve special files
and excludes:
-H, --hard-links preserve hard links
-A, --acls preserve ACLs (implies -p)
-X, --xattrs preserve extended attributes