How to create an RPM package
I. Introduction to RPM
RPM is the abbreviation of Red Hat Package Manager. It is intended to be the management of Red Hat software packages. As the name suggests, it is the management of software packages contributed by Red Hat. Now it should be the abbreviation of RPM Package Manager. Mainstream Release versions such as Fedora, RedHat, Mandriva, SUSE, and YellowDog, as well as the release versions developed on the basis of these versions. The RPM package includes the files required for running the program, there are also other files; an RPM package application sometimes requires other specific versions of files in addition to the additional files it carries to ensure its normality. This is the dependency of the software package.
RPM allows you to directly install the software package in binary mode and query whether the related library files have been installed for you. When you delete a program using RPM, it also intelligently asks the user whether to delete the relevant program. If you use RPM to upgrade the software, RPM retains the original configuration file so that you do not need to reconfigure the new software. RPM retains a database that contains all the software package materials. Through this database, you can query the software package. Although RPM is designed for Linux, it has been moved to SunOS, Solaris, AIX, Irix and other UNIX systems. RPM complies with the GPL copyright agreement, and users can freely use and disseminate RPM under the conditions that comply with the GPL protocol.
Ii. RPM package Classification
There are two types of rpm,
1 binary package, including rpm installation package (generally divided into i386 and x86) and debugging information package
2. Source Code packages. Source Code packages and Development kits should be replaced with such packages.
The relationship between them is that we first need to modify the software project source code according to rpm packaging requirements. When the requirements are met, we can use the rpmbuild command to generate different rpm packages, the versions generated at the same time correspond directly to each other. For example, if the source code package is the same, a binary rpm package is generated. When you search for rpm packages online, you can find pre-compiled Binary packages in the RPMS directory, while the source code package is in the SRPMS directory.
The RPM production mentioned here refers to the process of modifying the software source code to meet RPM packaging requirements. This can also be equivalent to the RPM source code package production process, because when you have the source code package, you can directly compile the binary installation package and any other packages.
Iii. Introduction to RPM package Creation
Create an RPM package, that is, create an RPM source package.
How RPM packages work
RPM is used to solve the problem that the source package is not easy to install (requires compilation) and the software package is dependent on each other (the RPM package manager can solve the dependency problem to a certain extent, it obtains the final generated file in the system to be installed by detecting the actions of the source code package in the build and install phases, record the necessary operations (for example, execute an operation after installation), and then combine them into a whole, when the user installs this package, it will take effect on the actual system for all the problems and operations recorded previously.
To compress a common source code into an RPM package, perform the following operations:
1. First, make necessary modifications to the project's Makefile to support the RPM packaging operation (in fact, this operation is not absolute, and the SPEC document and Makefile are coordinated and unified, it doesn't matter if they cooperate with each other. We generally recommend that you follow industry standards and specifications as much as possible)
2. Write the SPEC document for the current project. The SPEC document includes the operation content of the RPM packaging process and the basic information of the newly generated RPM package. The target object of this document is the package rpmbuild.
4. RPM package creation process
1. Prepare the Packaging Environment
Run the following commands to install rpmbuild and rpmdevtools:
# Yum install rpmbuild
# Yum install rpmdevtools
Run the following command to generate the rpmbuild working directory:
# Rpmdev-setuptree
The working directory structure is as follows,
~ /Rpmbuild
~ /Rpmbuild/SOURCES # Place packaging resources, including source package files and patch files
~ /Rpmbuild/SPECS # Place SPEC documents
~ /Rpmbuild/BUILD # working directory during packaging
~ /Rpmbuild/RPMS # store the generated Binary Package
~ /Rpmbuild/RPMS/i386 # store the generated i386 structure package
~ /Rpmbuild/SRPMS # store the generated source code package
Tip: The rpmdev-setuptree command will create an RPM in the current user's home directory by default to build the root directory structure. If you need to change the default location, you can modify the configuration file :~ /. The value corresponding to _ topdir in rpmmacros.
2. Load the source code to the SOURCES directory without Decompression
Cd SOURCES/
Wget http://nginx.org/download/nginx-1.2.1.tar.gz
3. Write a Spec File
SPEC writing is the core of packaging RPM, and it is also the most difficult step. Fortunately, we can start by referring to a simple template file, expand the document content step by step on the basis of the basic functions that can be implemented until the requirements are fully met. The following is a simple SPEC document, which includes some instructions (Note: # the following content is the description). This SPEC document is written for a tested software project hellorpm, after the hellorpm package is compiled, there is only one execution file, one manual file, and one project description file.
The content of nginx. spec is as follows:
#
# Example spec file for nginx
#
# Brief introduction to the software package
Summary: high performance web server
# Package name
Name: nginx
# Major version number of the software package
Version: 1.2.1
# Minor version number of the software package
Release: 1. el5.ngx
# Authorization Protocol
License: 2-clause BSD-like license
# Software Classification
Group: Applications/Server
Source: http://nginx.org/download/nginx-1.2.1.tar.gz
URL: http://nginx.org/
Distribution: Linux
Packager: zhumaohai <admin@www.bkjia.com>
# Description of the software package
% Description
Nginx [engine x] is a HTTP and reverse proxy server, as well
A mail proxy server
# Indicates the pre-operation field. The subsequent commands will be executed before the source code BUILD.
% Prep
Rm-rf $ RPM_BUILD_DIR/nginx-1.2.1
Zcat $ RPM_SOURCE_DIR/nginx-1.2.1.tar.gz | tar-xvf-
# The BUILD field will be compiled by directly calling the automatic BUILD tool in the source code directory
% Build
Cd nginx-1.2.1
# Call the configure command in the source code directory
./Configure -- prefix =/usr/local/nginx
# Execute the automatic build command make in the source code directory
Make
# Installation Field
% Install
Cd nginx-1.2.1
# Install and execute the script in the source code
Make install
% Preun
If [-z "'ps aux | grep nginx | grep-v grep '"]; then
Killall nginx>/dev/null
Exit 0
Fi
# Errors may occur if the file Description field is redundant or missing.
% Files
# Declare/usr/local/nginx to appear in the Software Package
/Usr/local/nginx
4. Create an RPM package
Start the build operation. First, go to the rpmbuild root directory of the current user.
# Cd ~ /Rpmbuild/
# Rpmbuild-ba SPECS/nginx. spec
Tip:-ba indicates build all, that is, all RPM packages including binary and source code packages are generated. If normal, rpmbuild Exits normally, at the same time, the corresponding RPM package will be generated in the RPMS directory and SRPMS directory.
You may also like the following content about RPM package creation:
How to quickly customize the binary kernel RPM package in CentOS
Getting started with creating an RPM package
In Linux, how does one create an RPM package?
Create your own rpm package
Directory structure and configuration after rpm installation in Linux
Brief Introduction and demo of rpm and yum
Redhat Linux --- rpm command details
Use FPM to easily create an RPM package
This article permanently updates the link address: