Getting started with creating an RPM package
Directory:
Specify the new workspace _ topdir
Create a working directory in the Workspace
Create a SPEC File
Create source file
Compile the RPM package
View the generated RPM package class capacity
Install and uninstall the generated RPM package
Important Fields in the SPEC File
Specify a new Workspace
_topdir
The default workspace is/usr/src/RedHatThrough the configuration filerpmmacrosSpecify:
cat>>~/.rpmmacros<<end > %_topdir /root/helloworld > end
This configuration can also be usedCommand LineTo specify:
rpmbuild --define "_topdir /root/helloworld"
Create a working directory in the Workspace
mkdir -p /root/helloworld/{RPMS,SRPMS,BUILD,SOURCES,SPECS}
Working directory explanation:
- Helloworld/BUILD: the command rpmbuild will decompress the source file in this directory and compile the program in this directory.
- Helloworld/SPECS: stores spec file spec files
- Helloworld/SOURCES: stores source files
- Helloworld/SRPMS: stores rpm files containing source code
- Helloworld/RPMS: stores rpm package files containing binary data
Create a SPEC File
helloworld/SPECS/hello.spec:
Summary: hello world rpm package Name: hello Version: 0.1 Release: 1 Source: %{name}-%{version}.tar.gz License: GPL Packager: amoblin Group: Application/System BuildRoot: %{_topdir}/root/ %description This is a software for making your life more beautiful! %prep rm -rf $RPM_BUILD_DIR/%{name}-%{version} zcat $RPM_SOURCE_DIR/%{name}-%{version}.tar.gz | tar -xv %build cd %{name}-%{version} gcc -o hello hello.c %install rm -rf %{buildroot} mkdir -p %{buildroot}/usr/local/bin/ cd %{name}-%{version} cp hello %{buildroot}/usr/local/bin/hello %files /usr/local/bin/hello
Create source file
hello.c:
#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
Package the source filesSOURCESDirectory
mkdir -p hello-0.1 mv hello.c hello-0.1 tar czvf hello-0.1.tar.gz hello-0.1 mv hello-0.1.tar.gz /root/helloworld/SOURCES/
Compile the RPM package
# Compile rpm rpmbuild-vv-ba helloworld/SPECS/hello. spec # or use the command line to specify topdir to compile rpmbuild -- define "_ topdir/root/helloworld"-vv-ba helloworld/SPECS/hello. spec # verify SPEC rpmbuild -- define "_ topdir/root/helloworld"-vv-bl helloworld/SPECS/hello. spec
View the generated RPM package class capacity:
[root@localhost ~]# rpm -qpil helloworld/RPMS/i386/hello-0.1-1.i386.rpm
Install and uninstall the generated RPM package
[root@localhost ~]# rpm -iv helloworld/RPMS/i386/hello-0.1-1.i386.rpm Preparing packages for installation... hello-0.1-1 [root@localhost ~]# hello Hello, World! [root@localhost ~]# rpm -ev hello-0.1-1
Important Fields in the SPEC file:
- Group: you must first define [
less /usr/share/doc/rpm-*/GROUPS]
- BuildRoot: installation phase
installIn%buildAfter the stage). The default root directory is%{_topdir}/BUILDROOT/
- % Prep:
prepareShell script called during preparation
- % Build:
buildShell scripts called during compilation
- % Install:
installShell script called during installation
Note: Run% Prep,% Build,% InstallShell scriptpwdDirectory:/root/helloworld/BUILD
- % Files: Specify which files are included in the generated binary RPM package. These files must be
BuildRootDirectory exists
In Linux, how does one create an RPM package?
This article permanently updates the link address: