Create an RPM package under CentOS6.x

Source: Internet
Author: User
Tags rpmbuild

0: This document uses the installation package of asterisk under centOS6.5 as an example to illustrate the problem. Please refer to the following example. Thank you! 1. Prepare the environment:

When installing the environment, you must have System Management permissions. However, when creating an RPM package, you must use a user without system management permissions to perform operations. Before you start all preparations, make sure that gcc and make are installed in your work environment. The installation methods of these two tools are not described here.

1.1 install components

Run the following command to install rpm-build:

Sudo yum install rpm-build

Run the following command to install redhat-rpm-config:

sudo yum install redhat-rpm-config

PS: Install rpmdev-newspec if necessary. This tool is used to generate a. spec file template. Because it is not a required tool, the installation and usage of it will not be described here.

1.2 create required folders and files in the user's home directory

Use the following command to create necessary folders, where BUILD is used to save the temporary files generated during the packaging process; RPMS is used to save the generated binary RPM package; SOURCES is used to save the packaged source files (including compressed files); SPECS is used to save. spec script; SRPMS is used to save the generated source code rpm package.

mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

Use the following command to generate the macro file required by rpmbuild. This file contains the relative path to be referenced in. spec. The content in the file can be manually configured and written, and the format meets the requirements.

echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
2. Create a. spec File

Here we use the asterisk binary rpm package as an example to illustrate how to create a. spec file. All. spec files can be created by reference and analogy.

2.1.spec File Format

Use the following command to generate asterisk. spec

cd ~/rpmbuild
vi ./SPECS/asterisk.spec

I entered the following content into the file.

Name: asterisk
Version: 1.8.15
Release: 1%{?dist}
Summary: Design by wanzhao
Group: Applications/Internet
License: GPL
URL: www.wanzhao.com
Source0: certified-asterisk-1.8.15-current.tar.gz
 
%description
Design by Wanzhao
 
%prep
cd $RPM_BUILD_DIR
tar xzvf ../SOURCES/certified-asterisk-1.8.15-current.tar.gz
 
%build
cd $RPM_BUILD_DIR/certified-asterisk-1.8.15-cert5
./configure
make
 
%install
cd $RPM_BUILD_DIR/certified-asterisk-1.8.15-cert5
make install
make samples 
cd ../BUILDROOT
cp -fr /etc/asterisk ./asterisk-1.8.15-1.x86_64/
 
%files
/asterisk/
 
%clean
rm -rf $RPM_BUILD_DIR/certified-asterisk-1.8.15-cert5
2.2asterisk Content Description

Name:

The name of the software package. The RPM Software Package uses the name and version number, and the release number and system number are used to name the software package.

Version:

The software version. The version number is added only when the software package has changed significantly.

Release:

The release number of the software package. Generally, when we make small patches for the software package, we should add the release number to 1.

Copyright:

The copyright rules used by the software package. Specifically: GPL (Free Software), BSD, MIT, Public Domain (Public Domain), Distributable (Contribution), commercial (business), Share (Share), etc, generally, GPL is used for development.

Group:

The category of the software package. The specific categories include:

Amusements/Games (entertainment/Games)

Amusements/Graphics (entertainment/Graphics)

Applications/Archiving (Application/Document)

Applications/Communications (Applications/Communications)

Applications/Databases (Application/database)

Applications/Editors (Application/editor)

Applications/Emulators (Application/simulator)

Applications/Engineering (Application/Engineering)

Applications/File (Application/File)

Applications/Internet (Applications/Internet)

Applications/Multimedia (Application/Multimedia)

Applications/productiinstances (Applications/products)

Applications/Publishing (Application/printing)

Applications/System (Application/System)

Applications/Text (Application/Text)

Development/Debuggers (Development/debugger)

Development/Languages)

Development/Libraries (Development/function library)

Development/System (Development/System)

Development/Tools (Development/Tools)

Documentation (document)

System Environment/Base (System Environment/basics)

System Environment/Daemons (System Environment/Daemons)

System Environment/Kernel (System Environment/Kernel)

System Environment/Libraries (System Environment/function library)

System Environment/Shells (System Environment/interface)

User Interface/desktop tops (User Interface/desktop)

User Interface/X (User Interface/X Window)

User Interface/X Hardware Support (User Interface/X Hardware Support)

Source:

The name of the source program package. If there are multiple files or parts that can be written: Source0 ......; Source1 ......; Soure3 ......;......

% Description:

Detailed description of the software package, which can be written on multiple rows.

% Prep

This section is a pre-Processing Section, which is usually used to execute some commands to unbind the source program package and prepare for the next compilation and installation. The % prep is the same as the % build and % install segments below. You can run the shell command. For example, we have added tar and cd commands.

% Build segment

This section is the compilation section. The command to be executed is the generated Software Package Service, such as./configure and make commands.

% Install segment

This section is the installation section, where the command will be executed when installing the software package, such as make install. Commands vary depending on different software.

% Files

This section is a file segment used to define the files contained in the generated rpm package. Therefore, files in the rpm package must be listed here. If this segment is missing, the binary rpm file cannot be generated.

% Clean Section

This section is designed to clean up junk files generated by the previous steps. Similarly, this segment consists of shell commands.

3. Package

If you only package a binary rpm package, run the following command:

rpmbuild –bb ****.spec

If you only package the source code rpm package, run the following command:

rpmbuild –bs ****.spec

If both the binary rpm package and the source code rpm package are required, run the following command:

rpmbuild –ba ****.spec

4. References:

Http://wiki.centos.org/HowTos/SetupRpmBuildEnvironment

Http://tecadmin.net/create-rpm-of-your-own-script-in-centosredhat/

Https://fedoraproject.org/wiki/How_to_create_a_GNU_Hello_RPM_package

Http://www.ibm.com/developerworks/cn/linux/l-rpm/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.