Linux Package Manager-RPM

Source: Internet
Author: User

Linux Package Manager-RPM

In the early days when we used source code to install software, we had to compile the source code into executable binary installation programs and then install them. This means that each installation of software requires preprocessing --> Compilation --> link --> generation of installation files --> Installation, which is a complex and difficult process. To simplify the installation steps and facilitate the installation and deployment of programs, the program provider compiles and packages the installation files of related programs on a specific system and provides them for download, we only need to download the corresponding installation package based on our own system for installation. It is similar to the installation method of Windows, which is compiled by program developers directly on known systems, then install the program directly to the user. But how should we manage the packages? This is what happens to our package manager!

What is the package manager?
The software used to manage software packages in Linux has the following functions: package compiled programs into one file or a limited number of files for installation, uninstallation, upgrade, query, and other functions.
Two mainstream package managers
Dpkg: It was first developed by the Debian Linux community. Most of the other Linux distributions derived from destdebian use dpkg to manage software, including B2D and Ubuntu, its front-end tools include apt-get.
RPM: It was first developed by Red Hat, and later it was really easy to use. Therefore, many distributions use it as a management method for software installation. Including Fedora, CentOS, and SUSE. Its front-end tools include yum.

Package composition format and storage path:
1. Binary Program
Main storage paths:/bin,/sbin,/usr/bin,/usr/sbin,/usr/local/bin,/usr/local/sbin, /usr/local/APP/{bin, sbin}
Note: Some special applications are stored in the libexec directory; some third-party applications are installed in the/opt directory by default.
2. database files (Development and running databases)
Main storage path:/lib64,/usr/lib64,/usr/local/lib64,/usr/local/APP/lib
3. Configuration File
Main storage path:/etc,/usr/local/APP/etc or conf directory
4. Help File
Main storage path:/usr/share/man,/usr/local/share/man,/usr/local/APP/man

RPM package manager Usage Details
RPM package naming format:


However, a program may have many functions, some of which are common functions, some are special functions, and some are secondary development-related functions. If all the functions are packaged together, without a doubt, the package will increase a lot. Some common users need to download and install all the functions they don't need, which may cause a waste of resources, the package mechanism is derived from the package. Generally, the program is divided into the main package and sub-package. For example, A bash program has 20 functions: 10 common functions, Special A: 4, special B: 3, and secondary development functions: 3, the package naming method is as follows:
Core Package, main package: Same name as source program
Bash-4.2.3-3.centos7.x86_64.rpm
Sub-package:
Bash-a-4.2.3-3.centos7.x86_64.rpm
Bash-b-4.2.3-3.centos7.x86_64.rpm
Bash-devel-4.2.3-3.centos7.x86_64.rpm


RPM-installation package:
Command Format: rpm [option]/path/to/package_file...
Common options:
-I: Install the program;
-V: displays the installation and execution process;
-Vv: Detailed installation and execution process;
-Vvv: displays the installation and execution process in more detail;
-H: Use # to mark the installation progress.
Common combination options:-ivh
-- Test: Only for testing, no installation is actually performed
-- Nodeps: Ignore dependency, force install, and install, but may not run
-- Replacepkgs: re-install. If the original configuration file is modified, it is likely that the configuration file generated by the installation will be renamed as. rpmnew.
[Root @ CentOS6 Packages] # rpm-ivh zsh-4.3.10-7.el6.i686.rpm -- test
Preparing... ######################################## ### [100%]
[Root @ CentOS6 Packages] # rpm-ivh zsh-4.3.10-7.el6.i686.rpm
Preparing... ######################################## ### [100%]
1: zsh ####################################### #### [100%]

[Note]: This command is followed by an RPM package file. You can use spaces to separate and Install multiple programs. For example, if your computer can access the Internet, you can also directly specify the RPM package on the network for installation.

RPM-uninstall package:

Command Format: rpm [option] package_name
Description of common options:-e: uninstall the program
-- Nodeps: Ignore dependencies and force Uninstall. Other programs dependent on this package may not run normally.
[Root @ CentOS6 Packages] # rpm-e zsh
Warning:/etc/zshrc saved as/etc/zshrc. rpmsave # Modify/etc/zshrc, prompting that the file will not be deleted and saved as/etc/zshrc. rpmsave
[Root @ CentOS6 Packages] # rpm-e httpd # uninstall httpd, prompting that other programs depend on this program and cannot be uninstalled. If you need to uninstall the programs that are dependent first
Error: Failed dependencies:
Httpd> = 2.2.0 is needed by (installed) gnome-user-share-2.28.2-3.el6.i686
[Root @ CentOS6 Packages] # rpm-e httpd -- nodeps # ignore dependency and forcibly uninstall
[Root @ CentOS6 Packages] #

[Note]: If the configuration file of the package has been changed after installation, it will not be uninstalled but will be renamed and retained. For example
Warning:/etc/zshrc saved as/etc/zshrc. rpmsave


RPM-upgrade package
Command Format: rrpm [-Uvh |-fvl]/path/to/package_file
Description of common options:-Uvh: upgrade or installation. If the program is installed on the computer, upgrade it. If the program is not installed, install it now;
-Fvl: upgrade only the programs installed on the computer. If not, do not install the programs;
-- Force: force update
[Note]: to ensure the normal operation of the system, do not upgrade the kernel. Instead, install the kernel. The system allows multiple Kernels to coexist.


RPM-query operation

Command Format: rpm [option] package_name | file
Common options:
-Q: Check whether a package is installed. Multiple packages can be queried at a time and separated by spaces;
[Root @ CentOS6 cd] # rpm-q zsh
Zsh-4.3.10-7.el6.i686

-Qa: Query all installed packages. You can filter the packages by conditions in the MPs Queue (rpm-qa | grep 'pattern ')
[Root @ CentOS6 cd] # rpm-qa
Libaio-0.3.107-10.el6.i686
Perl-URI-1.40-2.el6.noarch
Kbd-1.15-11.el6.i686
Gnome-speech-0.4.25-3.1.el6.i686
Cas-0.15-1.el6.1.noarch
Tzdata-2013g-1.el6.noarch
Libsss_autofs-1.9.2-129.el6.i686
.........
[Root @ CentOS6 cd] # rpm-qa | grep "zs .*"
Zsh-4.3.10-7.el6.i686

-Qi: query the description of a package (only the description of installed packages can be queried );
[Root @ CentOS6 cd] # rpm-qi zsh
Name: zsh Relocations: (not relocatable)
Version: 4.3.10 Vendor: CentOS
Release: 7. el6 Build Date: Sun 24 Nov 2013 12:37:44 EST
Install Date: Tue 21 Apr 2015 11:29:57 am edt Build Host: c6b9.bsys.dev.centos.org
Group: System Environment/Shells Source RPM: zsh-4.3.10-7.el6.src.rpm
Size: 4777026 License: BSD
Signature: RSA/sha1. Sun 24 Nov 2013 02:30:40 EST, Key ID 0946fca2c105b9de
Packager: CentOS BuildSystem URL: http://zsh.sunsite.dk/
Summary: A powerful interactive shell
Description:
The zsh shell is a command interpreter usable as an interactive login
Shell and as a shell script command processor. Zsh resembles the ksh
Shell (the Korn shell), but has des incluenhancements. Zsh supports
Command line editing, built-in spelling correction, programmable
Command completion, shell functions (with autoloading), a history
Mechanic, and more.
[Root @ CentOS6 cd] #

-Ql: queries the files generated by a package installation (all );
-Qc: queries the configuration files generated by a package installation;
-Qd: query the help files generated by a package installation;
-- Q -- scripts package_name: query the script of the package;
There are four types of scripts:
Preinstall: a pre-installation script. installation steps are required before the package is installed.
Postinstall: script after installation
Preuninstall: script before uninstallation
[Root @ CentOS6 cd] # rpm-qc zsh
/Etc/skel/. zshrc
/Etc/zlogin
/Etc/zlogout
/Etc/zprofile
/Etc/zshenv
/Etc/zshrc
[Root @ CentOS6 cd] # rpm-qd zsh
/Usr/share/doc/zsh-4.3.10/BUGS
.....
/Usr/share/man/man1/zshall.1.gz
....
[Root @ CentOS6 cd] # rpm-q -- scripts zsh
Postinstall scriptlet (using/bin/sh ):
If [! -F/etc/shells]; then
.....
[Root @ CentOS6 cd] #


To query information about uninstalled packages, you only need to add-p to the options, as shown below:

-Qpi Package Description
-Files generated during qpl package installation
-Configuration file generated by qpc package installation
-Qpd package installation will generate a Help File
Query the package generated by which a file is installed: rpm-qf/path/to/some_file
[Root @ CentOS6 cd] # rpm-qf/bin/vi
Vim-minimal-7.2.411-1.8.el6.i686 # The/bin/vi file is generated by the installation package
[Root @ CentOS6 cd] #

RPM-Verification

Used to check whether the file attributes generated by package installation have changed
Command Format: rpm [option] package_name | file
Common options:
-V: the program name is added. If the file of the program changes, it is displayed;
-Va: displays all files on the system that may have been modified;
-Vp: the file name is added to it to display files that may have been changed in the program;
-Vf: the file name is added to it to show whether a file has been modified.
[Root @ CentOS6 cd] # rpm-V zsh
S.5..... T. c/etc/zshrc
[Root @ CentOS6 cd] #

Description of corresponding attribute bits:
S file Size differs indicates that the file Size has changed
The permissions or types of M Mode differs (except des permissions and file type) files are modified.
5 digest (formerly MD5 sum) differs file content changed
D Device major/minor number mismatch master/secondary Device number changed
L readLink (2) path mismatch path change
U User ownership differs owner changed
G Group ownership differs Group changed
T The modification time of the mTime differs file has changed
P caPabilities differ package capability changed
[Note] When a file attribute changes, the identifier of the corresponding attribute bit is displayed. If the attribute does not change, it is displayed.

RPM package verification and digital signature description:

RPM package verification mainly includes source legitimacy verification and package integrity verification.
Digital signature: the package producer uses one-way encryption to extract the signature of the original data, and then uses its own private key to encrypt this feature code, appended with the original data.
Verification process:
Premise: a reliable mechanism is required to obtain the public key of the package producer;
1. Use the producer's public key to decrypt the encrypted signature. decryption means that the source is legal;
2. Use the same intention encryption algorithm as the producer to extract the signature of the original data and compare it with the decrypted features. If the same, the integrity is normal;
Check the legitimacy and integrity of the rpm package Source:
The public key of the package creator imported to the current system:
Rpm -- import/path/to/key_file
Display All imported public keys in gpg format:
Rpm-qa gpg-pubkey *
[Root @ CentOS6 cd] # rpm-qa gpg-pubkey *
Gpg-pubkey-c105b9de-4e0fd3a3
[Root @ CentOS6 cd] #

Displays the details of a key.

Rpm-qi gpg-pubkey-NAME
[Root @ CentOS6 cd] # rpm-qi gpg-pubkey-c105b9de-4e0fd3a3
Name: gpg-pubkey Relocations: (not relocatable)
Version: c105b9de Vendor: (none)
......
----- End pgp public key block -----

[Note] during installation, the imported Public Key is automatically used to verify the package. Manual verification is not required.

Manual check:
Rpm {-K | -- checksig} [-- nosignature] [-- nodigest] PACKAGE_FILE
Option description:
-K: equivalent to -- checksig. Check and display the result;
-- Nodigest: the integrity of the package is not checked;
-- Nosignature: The Source validity is not checked.
[Root @ CentOS6 cd] # cd Packages/
[Root @ CentOS6 Packages] # rpm-K zsh-4.3.10-7.el6.i686.rpm
Zsh-4.3.10-7.el6.i686.rpm: rsa sha1 (md5) pgp md5 OK
[Root @ CentOS6 Packages] # rpm -- checksig zsh-4.3.10-7.el6.i686.rpm
Zsh-4.3.10-7.el6.i686.rpm: rsa sha1 (md5) pgp md5 OK
[Root @ CentOS6 Packages] # rpm-K -- nodigest zsh-4.3.10-7.el6.i686.rpm
Zsh-4.3.10-7.el6.i686.rpm: rsa (md5) pgp OK
[Root @ CentOS6 Packages] # rpm-K -- nosignature zsh-4.3.10-7.el6.i686.rpm
Zsh-4.3.10-7.el6.i686.rpm: sha1 md5 OK


RPM-database reconstruction:
Database Directory:/var/lib/rpm
Rebuilding the database:
Rpm -- initdb: initialization
If no database exists, a new one is created. If yes, no new one is created;
Rpm -- rebuilddb: Rebuilding
Direct reconstruction, covering the original database

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:

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.