Management of the rpm package

A, rpm package management

Summary:

In the GNU / Linux operating system, RPM and DPKG for the two most common package management tools, they were used in Linux distributions based on the Linux distribution RPM and DEB packages packages. Role package management tool is provided in the operating system install, upgrade, methods to uninstall the software needed, and to provide access for all software system status information.
RPM (The RPM PackageManager), was developed by Red Hat Linux package installation and management of a program, a database record is one kind of approach to the software needed to install a management mechanism of your Linux system. Users can easily install the Linux system, upgrade, and remove software, and manage all RPM packages in a unified interface.

RPM package into binary packages (Binary), the source packet (Source) and Delta packages in three. Binary packages (.rpm) may be directly installed in the computer, and the source code package will be automatically compiled by the RPM, the installation. Source package as often src.rpm extension.

Features:
The software you want to install the first compiled and packaged into RPM package file mechanism through packaged software inside the default database records, property records dependency software when the software is to be installed must have, when installed in when your Linux box, RPM will first query data in accordance with the software inside the Linux host software meets the dependency property, if it is to be installed to meet, if not meet the production is not installed. Then the installation of the software on the information written to the entire RPM database for future inquiries, verification and uninstall.

rpm package command format

          Name-Version-Relase.Arch.rpm
                 eg:bash-4.1.2-15.el6_4.x86_64
Name:软件的名称,bash
Version: 版本信息。同源代码(4.1.2)  
源代码的version:major.minor.release 
Release: rpm自身释放的发行号(次数),通常是编译的次数。与程序源码的发行号无关,仅用于标识对rpm包不同制作的修订;同时,release还包含此包适用的OS
Arch:硬件平台,
       x86: i386, i486, i586, i686等;
       x86_64: 针对64位的CPU进行优化编译设定
       powerpc: ppc
       noarch: 依赖于虚拟机,没有任何硬件等级上的限制。
    例如:bash-4.2.3-3.centos5.x86_64.rpm

Way to get rpm package:

   1、发行的光盘或站点服务器
       镜像:
         http://mirrors.163.com
         http://mirrors.sohu.com
         http://centos.ustc.edu.cn/centos/
   2、项目的官网
        源代码
         rpm包
   3、很多第三方机构或个人制作并公开发布许多rpm包
         http://rpmfind.net
         http://rpm.pbone.net
   4、可靠的途径:EPEL
    EPEL是Extra Packages forEnterprise Linux的缩写,企业版 Linux 附加软件包。https://fedoraproject.org/wiki/EPEL/zh-cn

Legality verification rpm package:

包制作者制作完成之后会附加数字签名于包上;
来源合法性   
包的完整性
包的制作者使用单向加密提取原始数据的特征码,而后使用自己的私钥加密这段特性码,附加原始数据后面。

Verification process:

前提:必须有可靠机制获取到包制作者的公钥;
1、使用制作者的公钥解密加密的特征码,能解密则意味着来源合法;
2、使用与制作者同样的意向加密算法提取原始数据的特征码,并与解密出来的特征作比对,相同,则意味着完整性没问题;

rpm命令使用方法:

Installing RPM packages, delete, update, review and verification of all operations by the command rpm carried out. There are 12 rpm command modes, different modes have different command mode to complete different management functions. Commonly used modes are:

安装模式:rpm  {-i |--install}  [install-options]  PACKAGE_File …
升级模式:rpm  {-U|--upgrade}  [install-options]  PACKAGE_File …
卸载(删除)模式:rpm {-e|--erase} [erase-options]PACKAGE_Name …
查询模式:rpm  {-q |--query }  [select-options]  [query-options]
验证模式:rpm  {-V |--verify}  [select-options]  [verify-options]
一般选项:可以用于rpm命令的所有模式。
   -h :用#显示完成的进度。

   --version:显示当前使用的RPM版本。

Select the option: select-options, query and validate models.

        -a:查询所安装的软件包。
        -f,--file FILE :查询拥有<文件>的软件包,即是哪一个软件包安装的<解文件>。

Query Options: query-options, can be used to query and validate models.

   -i,--info:显示软件包的信息,包括名称、版本、描述信息。
   -l,--list:列出这个软件包内所包含的文件。
   --provides:显示这个软件包所提供的功能。
   -R,--requires:查询安装该软件包所需要的其他软件包。
   -s,--state:列出软件包中所有文件的状态。

Authentication options: verify-options, can only be used to verify the model.

   --nodeps:不验证依赖的软件包。
   --nofiles:不验证软件包文件的属性。

Installation options: install-options, for installation mode and upgrade mode.

   --force:同--replacepkgs,--replacefiles一样,就算要安装的软件版本已经安装在系统上,或者是系统上现在的版本比要安装的版本高,依然强制覆盖安装。
   --nodeps:使用RPM安装前,RPM会检查该软件包的依赖关系,即正确运行该软件包所需的其他软件是否已经安装。使用该选项将忽略软件包所依赖的其他软件强制安装。但不推荐这种做法,因为这样安装的软件大部是不能运行的。
   --test:模拟安装,软件包并不会实际安装到系统中,只是检查并显示可能存在的冲突。

Delete option: erase-options, it can only be used to delete mode.

   --nodeps:忽略其他依赖该软件包的软件,强制删除该软件包。正常情况下不建议这样做,因为删除软件包后,其他相关的软件就不能运行了。
   --test:不真正删除,只是模拟。

Common usage scenarios rpm package manager

Install the package: -i, - install

Installation package is divided into two stages, the first is to install the preparatory stage in the preparation phase will check disk space, the software has been installed, is dependent packages and other installed packages will be installed after the completion of the preparation phase.

-i,--install 安装新软件包。可用于内核的升级和安装,可以同时保留老内核版本和新版本两个内核。
-h,--hash 用#(hash)符显示rpm安装过程
-v,--verbose详述安装过程
-vv ,显示调试信息 
常用组合选项:-ivh
--test:安装准备阶段,模拟安装,检查为了检查一个软件包的安装是否会有冲突,可以事先使用--test选项进行模拟安装,例如
[root@gumt Packages]# rpm-ivh --test zsh-4.3.10-7.el6.x86_64.rpm 
Preparing...                ###########################################[100%]
[root@gumt Packages]# rpm-ivh zsh-4.3.10-7.el6.x86_64.rpm 
warning:zsh-4.3.10-7.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de:NOKEY
Preparing...                ###########################################[100%]
   1:zsh                  ###########################################[100%]

RPM package is likely to depend on other packages, which means that we can install the package after a specific package is installed. If the software is dependent on other packages are:

1, resolve dependencies

If interdependence among multiple packets may be used simultaneously rpm command to install a plurality of packages, or to install using yum.

There are dependencies of the package will be error, error: Faileddependencies :. The installation dependencies prompts, some of> =, <= symbol.

=: That must be greater than or equal to a version.

<=: It represents less than or equal to a version.

2, ignoring dependencies

--nodeps,强制安装软件包,但有可能无法运行;一般不建议。
[root@gumt Packages]# rpm -ivh --test libgnomecanvas-devel-2.26.0-4.el6.x86_64.rpm 
error: Faileddependencies:
         gtk-doc is needed bylibgnomecanvas-devel-2.26.0-4.el6.x86_64
         gtk2-devel >= 2.1.2 is needed bylibgnomecanvas-devel-2.26.0-4.el6.x86_64
         libart_lgpl-devel >= 2.3.8 is neededby libgnomecanvas-devel-2.26.0-4.el6.x86_64
         libglade2-devel >= 2.6.3-2 is neededby libgnomecanvas-devel-2.26.0-4.el6.x86_64
         pkgconfig(gail) is needed bylibgnomecanvas-devel-2.26.0-4.el6.x86_64
         pkgconfig(gtk+-2.0) is needed bylibgnomecanvas-devel-2.26.0-4.el6.x86_64

[root@gumt Packages]# rpm -ivh --nodeps libgnomecanvas-devel-2.26.0-4.el6.x86_64.rpm 
Preparing...               ########################################### [100%]
   1:libgnomecanvas-devel   ###########################################[100%]
--force:同 --replacepkgs,--replacefiles一样,就算要安装的软件版本已经安装在系统上,或者是系统上现在的版本比要安装的版本高,依然强制覆盖安装。

Uninstaller package: -e, - erase

rpm [option] package_name
-e: erase 删除软件包
--test模拟删除,可以先检查被删除软件包是否有依赖软件包
--nodeps,强制删除,忽略依赖关系,但依赖于此包程序包可能会运行不正常;同安装的选项类似。     

Note: When you uninstall, if the original configuration file has been modified, the system prompts a warning message, and installs generated configuration file is renamed to end with .rpmsave.

[root@gumt Packages]# rpm -e --test libgnome 
error: Failed dependencies:
         libgnome-2.so.0()(64bit)is needed by (installed) libbonoboui-2.24.2-3.el6.x86_64
         libgnome-2.so.0()(64bit)is needed by (installed) gnome-power-manager-2.28.3-7.el6_4.x86_64
         libgnome-2.so.0()(64bit)is needed by (installed) gnote-0.6.3-3.el6.x86_64
         libgnome-2.so.0()(64bit)is needed by (installed) mousetweaks-2.28.2-1.el6.x86_64
         libgnome >= 2.8.0 isneeded by (installed) gnome-python2-gnome-2.28.0-3.el6.x86_64
         libgnome is needed by(installed) gnome-terminal-2.31.3-8.el6.x86_64

[root@gumt Packages]# rpm -e --nodeps libgnome

Query package: -q, - query

使用rpm命令可以查看指定软件包的详细信息、安装的文件清单、依赖的软件包清单、某个软件包是否已经安装、系统中所有已安装软件包的清单等信息。

常用组合选项:
-q,--query查询某软件包是否安装,如果有则表示软件全名。
格式:rpm -qpackage_name...

# rpm -q bash
bash-4.1.2-15.el6_4.x86_64

-aq      ,--all查询系统中所有已经安装的软件包列表
按条件过滤:rpm -qa | grep 'PATTERN'等同于选项-qi

-iq,--info查询软件包的详细描述信息。输出中包括软件名称(name)、版本(Version)、修正版(Release)、软件包的安装时间(Install Date)、安装软件包的文件名称(Source RPM)、程序的占用空间(Size)   
[root@gumt Packages]# rpm -qi bash
    Name        : bash                         Relocations: (not relocatable)
    Version     : 4.1.2                             Vendor: CentOS
    Release     : 15.el6_4             Build Date: Thu 18 Jul 201309:21:24 PM CST
    Install Date: Mon 30 Jun 2014 12:27:55 PM CST      Build Host: c6b10.bsys.dev.centos.org
    Group       : SystemEnvironment/Shells     Source RPM:bash-4.1.2-15.el6_4.src.rpm
    Size        : 3139291                          License: GPLv3+
    Signature   : RSA/SHA1, Thu 18Jul 2013 09:46:10 PM CST, Key ID 0946fca2c105b9de
    Packager    : CentOS BuildSystem<http://bugs.centos.org>
    URL         :http://www.gnu.org/software/bash
    Summary     : The GNU BourneAgain shell
    Description :
    The GNU Bourne Again shell (Bash) is a shell or command language
    interpreter that is compatible with the Bourne shell (sh). Bash
    incorporates useful features from the Korn shell (ksh) and the C shell
    (csh). Most sh scripts can be run by bash without modification.
-lq,--list   查询系统中已安装软件包生成的文件列表。

      rpm -ql package_name
  [root@gumt Packages]# rpm -ql bash
    /bin/bash
    /bin/sh
    /etc/skel/.bash_logout
    /etc/skel/.bash_profile
    /etc/skel/.bashrc
    /usr/bin/bashbug-64
    /usr/share/doc/bash-4.1.2/COPYING
    … … … ….
-cq,--configfiles查询某包安装生成了哪些配置文件

#rpm -qc bash
         /etc/skel/.bash_logout
        /etc/skel/.bash_profile
        /etc/skel/.bashrc

-dq,--docfiles查询某包安装生成了哪些帮助文件

#rpm -qd bash
--scripts查询程序包的相关脚本

#rpm -q --scripts bash
显示的脚本有四类:
        preinstall:在安装之前运行脚本
        postinstall: 在安装之后脚本
        preuninstall: 在卸载之前脚本
        postuninstall: 在卸载之后脚本

-fq,--queryformat QUERYFMT查询某文件是由哪个软件包安装生成的。
    格式:   rpm -qf /path/to/some_file

# rpm -qf/bin/cat
        coreutils-8.4-31.el6.x86_64

-p,--package PACKAGE_FILE:对尚未安装的软件执行相关查询
    格式:    rpm [option] /path/to/package_file

可以结合选项-qpi、-qpl、-qpc、-qpd使用,查看未安装软件包的相关信息。
[root@gumt Packages]# rpm -q zsh
 package zsh is not installed
[root@gumt Packages]# rpm -qpc zsh-4.3.10-7.el6.x86_64.rpm 
    /etc/skel/.zshrc
    /etc/zlogin
    /etc/zlogout
    /etc/zprofile
    /etc/zshenv
    /etc/zshrc
-Rq,--requires查看已安装的某个软件包所依赖的软件包清单。格式:rpm –qR 软件包名称
[root@gumt Packages]# rpm -qR vim-common
/bin/sh  
config(vim-common) = 2:7.2.411-1.8.el6
libc.so.6()(64bit)  
libc.so.6(GLIBC_2.2.5)(64bit)  
libc.so.6(GLIBC_2.3)(64bit)  
libc.so.6(GLIBC_2.3.4)(64bit)  
libc.so.6(GLIBC_2.4)(64bit)  
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)  
rpmlib(PayloadIsXz) <= 5.2-1

Upgrade Package:

格式:rpm [option]/path/to/package_file

-U,--upgrade升级或安装。如果有老版本,则升级为新版本,否则安装。

Since version is too low, you want to upgrade to a newer version. The new version of the package installation files overwrite the old version of the file.

Users should be noted that: rpm will automatically uninstall the old version of the respective software package. If the software is not compatible with older versions of the configuration file on the new version, rpm will automatically save it as another file, the user will see the following message:
Saving /etc/foo.conf AS /etc/foo.conf.rpmsave
this users can change their own hand to the appropriate configuration files.
Also, if the user wants to install an older version of the software, the user will see the following error message:

-Uvh,如果有老版本,则升级为新版本,否则安装。

-F,--freshen纯升级,如果没有老版本,则不升级。

Combination of options: -Uvh, -Fvh

  升级后的版本可能会有依赖关系的冲突等;
  --force: 强制升级

Note: the general use of the kernel upgrade installation -ivh, rather than upgrade -Uvh (direct upgrade), the system allows the coexistence of multiple cores.

Package check: -V, - verify

-V,--verify用于检查包安装生成的文件属性是否发生变化。
格式:rpm -V package_name

检验项目共九项,结果以下面8个字母来和一个可能的属性标记:
        S : 表示文件大小;
        M : 表示权限;
        5 : 表示MD5检查和;
        D : 表示主从设备号;
        L : 表示符号连接;
        U : 表示属主;
        G : 表示属组;
        T : 表示最后修改时间根据文件类型的不同检验的项目也不同
        P:caPabilities differ
        c %config  configuration file.
        d %doc  documentation file.
        l %license  license file.
        r %readme  readme file.

某属性无变化,显示为.
示例:
[root@gumt Packages]# vi /etc/zshrc
[root@gumt Packages]# rpm -V zsh
S.5....T.  c /etc/zshrc

表示zsh包的配置文件/etc/zshrc文件大小、MD5、修改时间发生改变。

rpm package source of legitimacy and integrity of the test:

在安装软件的时候,会warning提示  NOKEY相关信息,说明rpm包对来源合法性验证有警示信息。需要在当前系统上导入包的制作者的公钥
[root@gumt Packages]# rpm -vhizsh-4.3.10-7.el6.x86_64.rpm
    warning: zsh-4.3.10-7.el6.x86_64.rpm:Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
    Preparing...                ###########################################[100%]
      1:zsh                  ###########################################[100%]
导入格式:#rpm --import/path/to/key_file

导入光盘镜像软件包公钥:

#rpm --import/media/cdrom/RPM-GPG-KEY-CentOS-6

 rpm -qa gpg-pubkey*    显示所有已经导入的gpg格式的公钥
 rpm -qi gpg-pubkey-NAME   #显示密钥的详细信息

Example:

 [root@gumt Packages]# rpm -K zsh-4.3.10-7.el6.x86_64.rpm 
    zsh-4.3.10-7.el6.x86_64.rpm: RSA sha1 ((MD5) PGP) md5 NOT OK (MISSINGKEYS: (MD5) PGP#c105b9de) 
  [root@gumt Packages]# rpm --checksig zsh-4.3.10-7.el6.x86_64.rpm 
    zsh-4.3.10-7.el6.x86_64.rpm: RSA sha1 ((MD5) PGP) md5 NOT OK (MISSINGKEYS: (MD5) PGP#c105b9de) 
  [root@gumt Packages]# rpm --import ../RPM-GPG-KEY-CentOS-6
  [root@gumt Packages]# rpm --checksig zsh-4.3.10-7.el6.x86_64.rpm 
    zsh-4.3.10-7.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
  [root@gumt Packages]# rpm -K zsh-4.3.10-7.el6.x86_64.rpm 
    zsh-4.3.10-7.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
手动检查:
        #rpm -K/path/to/package_file
        #rpm --checksig/path/to/package_file

不检查包完整性:
        #rpm -K --nodigest
不检查来源合法性:
        #rpm -K --nosignature

Database reconstruction:

     通过rpm 命令查询一个rpm 包是否安装了,也是要通过rpm 数据库来完成的;有时rpm 系统出了问题,不能安装和查询,可能会是数据库出现问题,可以使用下面命令重建;
rpm包数据库目录:/var/lib/rpm
#rpm --initdb:初始化数据库
    如果事先没有库,会新建一个;如果有,则不新建;
#rpm --rebuilddb: 重建数据库
        直接重建,覆盖原有的数据库

Guess you like

Origin blog.51cto.com/13369003/2424347