Getting started with creating an RPM package

Source: Internet
Author: User

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:

  1. Helloworld/BUILD: the command rpmbuild will decompress the source file in this directory and compile the program in this directory.
  2. Helloworld/SPECS: stores spec file spec files
  3. Helloworld/SOURCES: stores source files
  4. Helloworld/SRPMS: stores rpm files containing source code
  5. 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:
  1. Group: you must first define [less /usr/share/doc/rpm-*/GROUPS]
  2. BuildRoot: installation phaseinstallIn%buildAfter the stage). The default root directory is%{_topdir}/BUILDROOT/
  3. % Prep:prepareShell script called during preparation
  4. % Build:buildShell scripts called during compilation
  5. % Install:installShell script called during installation
    Note: Run% Prep,% Build,% InstallShell scriptpwdDirectory:/root/helloworld/BUILD
  6. % Files: Specify which files are included in the generated binary RPM package. These files must beBuildRootDirectory exists

In Linux, how does one create an RPM package?

This article permanently updates the link address:

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.