Make the source code package into an RPM package in Linux

Source: Internet
Author: User
Tags rpmbuild

Make the source code package into an RPM package in Linux

Step 1: first install the rpm-build package to generate the rpm package

[Root @ server1 ~] # Rpm-qa | grep rpm-build

[Root @ server1 ~] # Yum install-y rpm-build

Step 2: Create the httpd. spec File

Note: common users are required.

[Root @ server1 ~] # Useradd tom

[Root @ server1 ~] # Su-tom

[Tom @ server1 ~] $ Vim httpd. spec

[Tom @ server1 ~] $ Cat httpd. spec

Name: httpd //Program name

Version: 2.2.25 //Version Number

Release: 1% {? Dist}

Summary: compiled from 2.2.25 by zsp //Description, which can be customized

Group: System Environment/Daemons

License: GPL

URL: http://www.tarnea.com //Customize this information

Source0: httpd-2.2.25.tar.gz //Source file name, which must correspond to the following step 4.

BuildRoot: % (mktemp-ud % {_ tmppath}/% {name}-% {version}-% {release}-XXXXXX)

BuildRequires: gcc, gcc-c ++, openssl-devel //Software support required to generate an rpm package

Requires: wireshark-gnome //Run this rpm

% Description

Apache web server. Compiled from 2.2.25 by zsp

% Prep

% Setup-q

% Build

. /Configure -- prefix =/usr/local/httpd -- enable-so -- enable-rewrite -- enable-cgi -- enable-ssl -- enable-charset-lite -- enable-suexec --- suexec-caller = daemon -- with-suexec-docroot =/usr/local/httpd/htdocs

Make % {? _ Smp_mflags}

% Install //Initialize the installation directory before installation.

Rm-rf % {buildroot}

Make install DESTDIR = % {buildroot}

% Clean

Rm-rf % {buildroot}

% Files //Files generated after installation

% Defattr (-, root, root ,-)

% Defattr (-, root, root ,-)

/Usr/local/httpd/bin /*

/Usr/local/httpd/build /*

/Usr/local/httpd/cgi-bin /*

% Config/usr/local/httpd/conf /*

/Usr/local/httpd/error /*

/Usr/local/httpd/htdocs /*

/Usr/local/httpd/icons /*

/Usr/local/httpd/include /*

/Usr/local/httpd/lib /*

% Dir/usr/local/httpd/logs

% Doc/usr/local/httpd/man /*

% Doc/usr/local/httpd/manual /*

/Usr/local/httpd/modules /*

% Post //After installation, copy apachectl to myhttpd.

Cp/usr/local/httpd/bin/apachectl/etc/init. d/myhttpd

Sed-I '1a # chkconfig: 2345 85 15'/etc/init. d/myhttpd

Sed-I '2a # description: apache web server '/etc/init. d/myhttpd

Chkconfig -- add myhttpd

% Preun //Operations performed by detaching the rpm package

/Etc/init. d/myhttpd stop

Chkconfig -- del myhttpd

% Changelog //You can use rpm-q -- changelog httpd to define some log files.

* Wed Mar 26 2014 zhangzhg <zsp@tarena.com> 2.2.25

-First rpm from httpd-2.2.25

[Tom @ server1 ~] $

Step 3: Generate related directories

[Tom @ server1 ~] $ Ls

Httpd-2.2.25.tar.gz httpd. spec

[Tom @ server1 ~] $ Rpmbuild httpd. spec //Generate related directories with Error Type prompts, which is normal

Error: File/home/tom/rpmbuild/SOURCES/httpd-2.2.25.tar.gz: No such file or directory

[Tom @ server1 ~] $ Ls

Httpd-2.2.25.tar.gz httpd. spec rpmbuild //The rpmbuild directory appears after generation.

[Tom @ server1 ~] $ Ls rpmbuild/

Build buildroot rpms sources specs srpms // rpmbuildThese six directories exist in the directory.

Step 4: copy the file to the specified directory

[Tom @ server1 ~] $ Cp httpd. spec rpmbuild/SPECS/

[Tom @ server1 ~] $ Cp httpd-2.2.25.tar.gz (rpmbuild/SOURCES/

Step 5: generate an RPM package

[Tom @ server1 ~] $ Rpmbuild-ba rpmbuild/SPECS/httpd. spec

If the command cannot be executed, the system may prompt that gcc, gcc-c ++, and openssl-devel software are not installed. Exit the tom user and run yum to install the software. [root @ server1 ~] # Yum install-y gcc-c ++ openssl-devel

After the installation is complete, the rpm package is generated in the RPMS directory and the source package is generated in the SRPMS directory:

[Tom @ server1 ~] $ Ls rpmbuild/RPMS/x86_64/

Httpd-2.2.25-1.el6.x86_64.rpm

[Tom @ server1 ~] $ Ls rpmbuild/SRPMS/

Httpd-2.2.25-1.el6.src.rpm

[Tom @ server1 ~] $

Step 6: test the new RPM package

[Root @ server1 ~] # Cp/home/tom/rpmbuild/RPMS/x86_64/httpd-2.2.25-1.el6.x86_64.rpm.

[Root @ server1 ~] # Rpm-ivh httpd-2.2.25-1.el6.x86_64.rpm

//Because in httpd. the dependency is set in the spec file, so a wireshark-gnome dependency is prompted during installation. To verify the dependency options when rpm is created, you can install the SDK by ignoring the dependency.

Error: Failed dependencies:

Wireshark-gnome is needed by httpd-2.2.25-1.el6.x86_64

[Root @ server1 ~] # Rpm-ivh -- nodeps httpd-2.2.25-1.el6.x86_64.rpm //Ignore dependency Installation

Preparing... ######################################## ### [100%]

1: httpd ####################################### #### [100%]

[Root @ server1 ~] # Rpm-e -- nodeps httpd-2.2.25-1.el6.x86_64

Httpd (no pid file) not running

//Because myhttpd is not enabled, and the % preun option is set in the httpd. spec file, a prompt is displayed, indicating that httpd is not running.

[Root @ server1 ~] #


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.