How to Create a software package in Linux

Source: Internet
Author: User
Tags rpmbuild

In general, there are three main methods for installing software in Linux:
One is source code installation, which requires manual compilation by the user
The other is the RPM package (RedHat Linux Packet Manager), which can be installed through the RPM command.
Another method is the *. binfile, which is similar to the installation process in Windows.


Generally, the following two methods are used to install software in Linux:
① The file name is like xxx. i386.rpm. The software package is released in binary format.
② The file name is like xxx.tar.gz. The software package is released in the form of source code.
Linux software package management can be divided into three types: Binary Package management, source code package management, script Installation

In addition, it is worth noting that there are many ways to obtain and install software for various Linux releases.For example
[] Redhat/centos yum installation (with dedicated image sources)
[] Sudo apt-get of Ubuntu/Fedora/Debian is suitable for managing and installing deb packages.
[] Some software is installed with an encrypted disk (for example, cnyunwei)
[] In terms of system O & M management personnel, some software commands executed in ssh, C/C ++, or py are also used for automated management. I will not detail them here.

The following figure shows the architecture relationship of linux software applications:

When Linux is started. The kernel is a computer program that directly manages hardware, including CPU, memory space, hard disk interface, and network interface. All computer operations must be passed to the hardware through the kernel. We can see that Linux uses kernel to implement a conversation between hardware and software. Through this important interface called by the system, Linux completely separates upper-layer applications from lower-layer kernel, hiding the underlying complexity for programmers (correspondingly, it also improves the portability of upper-layer applications ). When upgrading the kernel, we can also keep the statements called by the system unchanged, so that upper-layer applications do not feel the changes at the lower layer. Library functions use system calls to create modular functions, while shell provides a user interface, allowing us to write scripts using shell syntax to integrate the program. With these ideas, we can quickly understand the installation and working principles of linux software applications, therefore, in order to facilitate and obtain more enterprise applications, we need to develop various software packages on the linux system and compile the source code to serve the information age.

This article describes how to install source code and RPM packages.

The source code package and commercial software package are based on the actual situation of each company or author (it can be a compressed package in tar or bin format, it can be a compiled file that can be directly used for running, or an iso file that can be created and released by other media such as the disc virtualization file) package it into a specific format and release it for corresponding software services. In fact, software installed using the yum or make install command will automatically generate an rpm package in the system (only the differences and rigor between parameters and functional modules)


Introduction:

RPM (RedHat Package Manager, Red Hat Package Manager) is used before installing, querying, upgrading, verifying, uninstalling software packages, and generating software packages in. rpm format RPM.

You can also download the free RPM package from the Internet.
# Mount/dev/cdrom --- attach a cd
# Cd/media/cdrom/CentOS/RPMS --- enter the RPM package directory on the disc (you can run the # mount command to check that the mount point of the disc is usually displayed on the last line)
# Ls

I. Install the source code package
1. * Source code package in the form of src. rpm
Usage:
Install: rpm-rebuild *. src. rpm
Cd/usr/src/dist/RPMS
Rpm-ivh *. rpm
Uninstall: rpm-e packagename

22.16.tar.gz, *. tgz, *. bz2 software package installation

First, decompress the package. The command is as follows:
Tar zxvf * .tar.gz
Tar xvfz *. tgz
Tar xvfj * .tar.bz2
Decompress the package and enter the decompressed directory)
Configuration:./configure
Compile: make
Install: make install
Uninstall: make uninstall

It is difficult to install the source code. Different software may be installed differently. Generally, you should read the instructions and install the software according to the instructions.

Ii. RPM package installation
The RPM installation package format was proposed by Redhat, which greatly simplifies the installation of software in Linux. First, we will introduce general options.

-V: displays additional information.

-Vv: displays debugging information.

-- Root directory: Let RPM use directory as the root directory, so that both the preinstallation program and the post-installation program will be installed in this directory.

1. Installation: rpm-I <options> file. rpm

Options:

H: Output hash mark during installation

Test: only tests the installation and does not install it.

-- Persent: displays the installation progress in percentages.

-- Excludedocs: Does not install the document in the Software Package

-- Replacepkgs: Force reinstall

-- Replacefiles: Replace the files of other software packages.

-- Force: ignore software packages and document conflicts

-- Ignorearch: the structure of the software package is not verified.

-- Ignoreos: the operating system that does not check the software package running

-- Nodeps: no dependency check

-- Noscripts: Do not run the pre-Installation and post-installation scripts

2. Delete rpm-e <option> pkgname

Option:

-- Test: only deletes the test and does not actually Delete the test.

-- Noscripts: Do not run the pre-Installation and post-installation scripts

-- Nodeps: no dependency check

Note: pkgname is the package name, not the rpm package name, but the package name after installation. You can use the query command to query the package name.

3. upgrade rpm-U (or-upgrade) <option> file. rpm

Option:

Similar to the option during installation, there are several special features:

-- Oldpackage: allows an old version

4. query rpm-q (or -- query) <option>

Option:

-P PACKAGE_FILE: query the package file

-F FIEL: queries the software package of the FILE.

-A: Query all installed software packages.

-G group: queries software packages that belong to the group.

-- WhatproVidesCAPABILITY: queries software packages that provide CAPABILITY.

-- WhatrequiresCAPABILITY: queries all software packages that require CAPABILITY.

-I: displays the summary of the software package.

-L: displays the file list in the software package.

-C: displays the configuration file list.

-S: displays the file list

-Scripts: displays the installation, uninstallation, and validation scripts.

-- Qf: queries in the way specified by the user

-- Dump: displays the verification information for each file.

-- ProVides: displays the functions provided by the software package.

-R: displays the functions required by the software package.

5. verify the installed software package rpm-V (or-verify, or-y) <option>

The Option is similar to that of other commands.

6. Verify the file rpm-K (or-checksig) <option> file. rpm in the software package.

Option:

-V: displays version information.

-Vv: displays debugging information.

-- Rcfile FILELIST: sets the rpmrc file to FILELIST.

7. Other RPM options

-- Rebuilddb: rebuilding the RPM Database

-- Initdb: Create a New RPM Database


-- Quiet: reduce output as much as possible

-- Help: displays the help file.

-- Version: displays the current version of RPM.

The above is just a summary of common options. If you have any questions, you can use the man rpm command to view them. The official file will always be the best teacher.

Iii. Installation of *. bin installation files

You only need to double-click the *. binfile to install it as prompted.

To create a software package in RPM format, you need to compile the software package description file. The standard naming format is: Software name-version number-Release number. spec (usually used directly in most cases: Software name. spec). This file describes a lot of information about the software package, such as the software name, version, category, description summary, what commands to execute during creation, and what operations to perform during installation, and the files to be included in the software package. With this file, RPM can produce the corresponding package file. Of course, there are also open-Source package preparation tools such as Source rpm, which can be created through the wizard as long as a program Source.

A simple example:

In fact, the best way is to make a software package. I remember that both rpm and debian have open-source software that can be quickly packaged and used directly.

Eg> Use nginx tar as the RPM package

1. Download The nginx source code package

2. Put the file in the/usr/src/redhat/SOURCES/directory.

3. Compile the SPEC File


[Root @ mail SPECS] # vinginx-0.8.35.spec

Summary: the first rpmpackage

Name: nginx

Version: 0.8

Release: 35

Vendor: chenwei01@corp.the9.com

License: Share

Group: Applications/Text

Source0: nginx-0.8.35.tar.gz

% Description

My test nginx

% Prep

Tar-zxvf $ RPM_SOURCES_DIR/nginx-0.8.35.tar.gz

% Build

Cd $ RPM_BUILD_DIR/nginx-0.8.35

./Configure

Make

% Install

Cd $ RPM_BUILD_DIR/nginx-0.8.35

Make install

% Clean

Rm-rf $ RPM_BUILD_DIR/nginx-0.8.35

% Files

% Defattr (-, root, root)

/Usr/local/nginx/sbin/nginx

% Doc $ RPM_BUILD_DIR/nginx-0.8.35/README

4. Create an RPM package
[Root @ mail SPECS] # rpmbuild-ba nginx-0.8.35.spec

If there is no error running, two files are generated:/usr/src/redhat/RPMS/i386/nginx-0.8-35.i386.rpm and/usr/src/redhat/SRPMS/nginx-0.8-35.src.rpm.

Summary: how to create an rpm package

1 RPM Introduction

RPM is the abbreviation of RedHat 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.

Binary RPM package Classification
In my opinion, rpm is divided into two categories,
1 binary package, including rpm installation package (generally divided into i386 and x86) and debugging information package.
2. The source code package, the source code package and the development kit should be replaced with this class.

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.

Introduction to making three RPM packages

Create an RPM package, that is, create an RPM source package.

Here I want to talk about how the RPM package works. This will help you fully understand the RPM package management system.

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 pack RPM for a common source code, you need to perform the following operations. First, you need to make necessary modifications to the project Makefile to support the RPM packaging operation (in fact, this operation is not absolute, SPEC documents and Makefile are coordinated and unified. It doesn't matter if they work together. We generally recommend that you follow industry standards and specifications as much as possible ); the second is to 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. Its role object is the package program rpmbuild.

4 RPM package creation process

1. Prepare the Packaging Environment
Run the following command in the fedora system to install rpmbuild:
# Yum install rpmbuild
The rpmbuild working directory is as follows,

~ /Rpmbuild

~ /Rpmbuild/SOURCES

~ /Rpmbuild/SPECS

~ /Rpmbuild/BUILD

~ /Rpmbuild/RPMS

~ /Rpmbuild/RPMS/i386

~ /Rpmbuild/SRPMS

If your user directory does not have a similar directory structure, you can use a tool software to automatically configure and generate the directory, as shown below.

# Yum installrpmdevtools

Run the automatic configuration command to automatically generate the above directory and configure some necessary operations.

# Rpmdev-setuptree

By default, the rpmdev-setuptree command creates an RPM in the current user's home directory 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.

Generally, rpmbuild automatically creates the above directory structure under the current user's home directory. If the above directory is not automatically created in the build directory of your corresponding user, you can create it manually. The above directory is allocated in this way. SOURCES places packaging resources, including source package files and patch files; SPECS directory places SPEC documents; BUILD working directory during packaging; the RPMS directory stores the generated Binary Package. The RPM package is classified based on the hardware platform. i386 indicates that the packages with the i386 structure will be stored in this directory. The SRPMS directory stores the generated source package.

2. Write SPEC documents
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 the hellorpm. spec document is as follows:
-----------------------------------------------------------------------------
# Brief introduction to the software package
Summary: hellorpm is atest program.

# Package name

Name: hellorpm

# Major version number of the software package

Version: 2.2.6

# Minor version number of the software package

Release: 1

# Source code package, which will be searched in the SOURCES directory mentioned above by default

Source0: % {name1_-1_version=.tar.gz

# Authorization Protocol

License: GPL

# Define the temporary build Directory, which will be referenced later as the temporary installation directory

BuildRoot: % {_ tmppath}/% {name}-% {version}-% {release}-root

# Software Classification

Group: Development/Tools

# Description of the software package

% Description

The hellorpm programis a test.

# Indicates the pre-operation field. The subsequent commands will be executed before the source code BUILD.

% Prep

# BUILD the BUILD Environment, decompress the source code package to the BUILD directory

% Setup-q

# The BUILD field will be compiled by directly calling the automatic BUILD tool in the source code directory

% Build

# Call the configure command in the source code directory

./Configure

# Execute the automatic build command make in the source code directory

Make

# Installation Field

% Install

# Install and execute the script in the source code

MakeDESTDIR = $ RPM_BUILD_ROOT install

# Errors may occur if the file Description field is redundant or missing.

% Files

# Setting File Permission attributes

% Defattr (-, root, root)

# Declare/usr/local/bin/hellorpm to appear in the package

/Usr/local/bin/hellorpm

# Declare and set file attributes

% Doc % attr (0444, root, root)/usr/local/man/man1/hellorpm.1

# Same as above, declare a document file

% DocREADME
-------------------------------------------------------------------------------
One point to note in this document:

BuildRoot: % {_ tmppath}/% {name}-% {version}-% {release}-root

The preceding BuildRoot variable indicates the temporary directory of the source code. rpmbuild obtains all the files to be retrieved from the system through the sub-directory, the parameter DESTDIR = $ RPM_BUILD_ROOT in the make install command after the SPEC file is a reference to this parameter, this parameter will be passed to the Makefile file. 1. The automatic build tool should install the file. (In fact, The Makefile I mentioned earlier must be transformed to adapt to RPM construction. This operation is included, in your Makefile file, you must at least know the value of this parameter referenced during RPM build to control the installation operation target ).

Compile a simple spec文, and put a compressed source code file named hellorpm-2.2.6.tar.gz

The SOURCES directory under the rpmbuild root directory (note, make sure that the directory after decompression of this archive file is hellorpm-2.2.6, otherwise there will be issues ).

By now, the complete rpm packaging environment has been built. Now we can start to build the binary and source code RPM packages.

3. Create an RPM package

The RPM package is built with the command rpmbuild completed under SPEC guidance.

Start the build operation. First, go to the rpmbuild root directory of the current user (that is, the directory environment mentioned above ).

# Cd ~ /Rpmbuild/

-Ba indicates build all, that is, all RPM packages including the Binary Package and source code package are generated. If the command runs normally, rpmbuild Exits normally, at the same time, the corresponding RPM package will be generated in the RPMS directory and SRPMS directory.

# Rpmbuild-baSPECS/hellorpm. spec

Here we only introduce the simplest RPM Packaging Process of the simplest software, for example, if a project with shared files needs to carry out complex configurations with complex dependencies, and so on, packaging and post-maintenance, including patch creation, I will complete additional updates at the next time, it's not too early today. It's time to rest!
Note: after a long time in the middle of the night, how much is the significance of such an unsatisfactory document? Do you dare not reinvent the wheel and stand on the shoulders of giants before you can see farther, right? Is it possible to set up a plan next week and translate at least three documents on the fedora official website every week for your trainer.

Related Article

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.