简介
RPM是RPMPackage Manager(RPM软件包管理器)的缩写,这一文件格式名称虽然打上了RedHat的标志,但是其原始设计理念是开放式的,现在包括OpenLinux、S.u.S.E.以及Turbo Linux等Linux的分发版本都有采用,可以算是公认的行业标准了。
●RPM数据库
●RPM软件包文件
●RPM可执行文件
默认使用RPM作为软件包管理器的OS,一般其RPM数据库信息存放于/var/lib/rpm/目录下。当我们使用rpm相关命令时,它会到数据库中查找相关的数据(软件包名,校验信息,依赖,已安装的软件包,软件包组…)。可以使用file命令查看目录下的文件信息,可以发现几乎都是二进制的数据库文件信息。
rpm重建数据库的命令是
rpm --rebuilddb
# file /var/lib/rpm/* /var/lib/rpm/Basenames: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Conflictname: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/__db.001: Applesoft BASIC program data /var/lib/rpm/__db.002: data /var/lib/rpm/__db.003: data /var/lib/rpm/__db.004: data /var/lib/rpm/Dirnames: Berkeley DB (Btree, version 9, native byte-order) /var/lib/rpm/Filedigests: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Group: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Installtid: Berkeley DB (Btree, version 9, native byte-order) /var/lib/rpm/Name: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Obsoletename: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Packages: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Providename: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Provideversion: Berkeley DB (Btree, version 9, native byte-order) /var/lib/rpm/Pubkeys: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Requirename: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Requireversion: Berkeley DB (Btree, version 9, native byte-order) /var/lib/rpm/Sha1header: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Sigmd5: Berkeley DB (Hash, version 9, native byte-order) /var/lib/rpm/Triggername: Berkeley DB (Hash, version 9, native byte-order) |
红帽或者一些开源组织使用rpm软件包文件发布软件,类似于tar归档文件打包。包文件中包含许多的信息(软件本身,包名,安装大小,软件包简述信息,依赖信息,包校验信息…)
包命名规则
例子:kernel-2.6.32-358.el6.i686
kernel |
软件包的名称 |
2.6.32 |
版本号 |
358 |
发行号 |
el6 |
发行商版本,适用于rhel6/centos6系统上 |
i686 |
x86硬件架构 |
RPM可执行文件是管理员操作rpm数据库的前端,通过可执行文件可达到不同功能安装,查询,卸载
安装命令:
rpm{-i|--install} [install-options] PACKAGE_FILE ...
-v:verbose
-vv:显示详细过程
-h:以#显示程序包管理执行进度;每个#表示2%的进度
rpm -ivh PACKAGE_FILE ...
常用的格式
# rpm -ivh lrzsz-0.12.20-36.el7.x86_64.rpm warning: lrzsz-0.12.20-36.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:lrzsz-0.12.20-36.el7 ################################# [100%] |
显示详细的安装过程
# rpm -ivvh lrzsz-0.12.20-36.el7.x86_64.rpm D: ============== lrzsz-0.12.20-36.el7.x86_64.rpm D: loading keyring from pubkeys in /var/lib/rpm/pubkeys/*.key D: couldn't find any keys in /var/lib/rpm/pubkeys/*.key D: loading keyring from rpmdb D: opening db environment /var/lib/rpm cdb:0x401 D: opening db index /var/lib/rpm/Packages 0x400 mode=0x0 D: locked db index /var/lib/rpm/Packages D: opening db index /var/lib/rpm/Name 0x400 mode=0x0 D: Expected size: 79376 = lead(96)+sigs(1284)+pad(4)+data(77992) D: Actual size: 79376 warning: lrzsz-0.12.20-36.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: added binary package [0] D: found 0 source and 1 binary packages D: opening db index /var/lib/rpm/Conflictname 0x400 mode=0x0 D: ========== +++ lrzsz-0.12.20-36.el7 x86_64/linux 0x2 D: opening db index /var/lib/rpm/Providename 0x400 mode=0x0 D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: libc.so.6()(64bit) YES (db provides) D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: libc.so.6(GLIBC_2.11)(64bit) YES (db provides) D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: libc.so.6(GLIBC_2.14)(64bit) YES (db provides) D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: libc.so.6(GLIBC_2.15)(64bit) YES (db provides) D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: libc.so.6(GLIBC_2.2.5)(64bit) YES (db provides) D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: libc.so.6(GLIBC_2.3)(64bit) YES (db provides) D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: libc.so.6(GLIBC_2.3.4)(64bit) YES (db provides) D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: libc.so.6(GLIBC_2.4)(64bit) YES (db provides) D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: libc.so.6(GLIBC_2.7)(64bit) YES (db provides) D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: libnsl.so.1()(64bit) YES (db provides) D: Requires: rpmlib(CompressedFileNames) <= 3.0.4-1 YES (rpmlib provides) D: Requires: rpmlib(FileDigests) <= 4.6.0-1 YES (rpmlib provides) D: Requires: rpmlib(PartialHardlinkSets) <= 4.0.4-1 YES (rpmlib provides) D: Requires: rpmlib(PayloadFilesHavePrefix) <= 4.0-1 YES (rpmlib provides) D: read h# 12 Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: Requires: rtld(GNU_HASH) YES (db provides) D: Requires: rpmlib(PayloadIsXz) <= 5.2-1 YES (rpmlib provides) D: opening db index /var/lib/rpm/Obsoletename 0x400 mode=0x0 D: ========== recording tsort relations D: ========== tsorting packages (order, #predecessors, #succesors, depth) D: 0 0 0 1 +lrzsz-0.12.20-36.el7.x86_64 D: installing binary packages D: closed db index /var/lib/rpm/Obsoletename D: closed db index /var/lib/rpm/Conflictname D: closed db index /var/lib/rpm/Providename D: closed db index /var/lib/rpm/Name D: closed db index /var/lib/rpm/Packages D: closed db environment /var/lib/rpm D: opening db environment /var/lib/rpm cdb:0x401 D: opening db index /var/lib/rpm/Packages (none) mode=0x42 D: sanity checking 1 elements D: opening db index /var/lib/rpm/Name (none) mode=0x42 D: running pre-transaction scripts D: computing 9 file fingerprints D: opening db index /var/lib/rpm/Basenames (none) mode=0x42 D: opening db index /var/lib/rpm/Group (none) mode=0x42 D: opening db index /var/lib/rpm/Requirename (none) mode=0x42 D: opening db index /var/lib/rpm/Providename (none) mode=0x42 D: opening db index /var/lib/rpm/Conflictname (none) mode=0x42 D: opening db index /var/lib/rpm/Obsoletename (none) mode=0x42 D: opening db index /var/lib/rpm/Triggername (none) mode=0x42 D: opening db index /var/lib/rpm/Dirnames (none) mode=0x42 D: opening db index /var/lib/rpm/Installtid (none) mode=0x42 D: opening db index /var/lib/rpm/Sigmd5 (none) mode=0x42 D: opening db index /var/lib/rpm/Sha1header (none) mode=0x42 Preparing... D: computing file dispositions D: 0x0000fd00 4096 4372384 18293084 / ################################# [100%] D: ========== +++ lrzsz-0.12.20-36.el7 x86_64-linux 0x2 D: Expected size: 79376 = lead(96)+sigs(1284)+pad(4)+data(77992) D: Actual size: 79376 D: lrzsz-0.12.20-36.el7.x86_64: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY D: install: lrzsz-0.12.20-36.el7 has 9 files Updating / installing... 1:lrzsz-0.12.20-36.el7 D: ========== Directories not explicitly included in package: D: 0 /usr/bin/ D: 1 /usr/share/locale/de/LC_MESSAGES/ D: 2 /usr/share/man/man1/ D: ========== D: create 100644 1 ( 0, 0) 14021 /usr/share/locale/de/LC_MESSAGES/lrzsz.mo;55e23296 D: create 100644 1 ( 0, 0) 5810 /usr/share/man/man1/rz.1.gz;55e23296 D: create 100644 1 ( 0, 0) 7383 /usr/share/man/man1/sz.1.gz;55e23296 D: create 100755 3 ( 0, 0) 0 /usr/bin/rb;55e23296 D: create 100755 3 ( 0, 0) 0 /usr/bin/rx;55e23296 D: create 100755 3 ( 0, 0) 76760 /usr/bin/rz;55e23296 D: create 100755 3 ( 0, 0) 0 /usr/bin/sb;55e23296 D: create 100755 3 ( 0, 0) 0 /usr/bin/sx;55e23296 D: create 100755 3 ( 0, 0) 80872 /usr/bin/sz;55e23296 ################################# [100%] XZDIO: 40 reads, 186156 total bytes in 0.010046 secs D: adding "lrzsz" to Name index. D: adding 9 entries to Basenames index. D: adding "Applications/Communications" to Group index. D: adding 16 entries to Requirename index. D: adding 2 entries to Providename index. D: adding 3 entries to Dirnames index. D: adding 1 entries to Installtid index. D: adding 1 entries to Sigmd5 index. D: adding "ea6a9195f414aea41862dc4242fd7345a1a6775f" to Sha1header index. D: running post-transaction scripts D: closed db index /var/lib/rpm/Sha1header D: closed db index /var/lib/rpm/Sigmd5 D: closed db index /var/lib/rpm/Installtid D: closed db index /var/lib/rpm/Dirnames D: closed db index /var/lib/rpm/Triggername D: closed db index /var/lib/rpm/Obsoletename D: closed db index /var/lib/rpm/Conflictname D: closed db index /var/lib/rpm/Providename D: closed db index /var/lib/rpm/Requirename D: closed db index /var/lib/rpm/Group D: closed db index /var/lib/rpm/Basenames D: closed db index /var/lib/rpm/Name D: closed db index /var/lib/rpm/Packages D: closed db environment /var/lib/rpm |
一些附加的安装选项
--test: 测试安装,但不真正执行安装过程;dry run模式;
--nodeps:忽略依赖关系;
--replacepkgs: 重新安装;
--nosignature: 不检查来源合法性;
--nodigest:不检查包完整性;
--noscipts:不执行程序包脚本片断;
%pre: 安装前脚本;--nopre
%post: 安装后脚本;--nopost
%preun: 卸载前脚本;--nopreun
%postun: 卸载后脚本; --nopostun
常用到的查询组合 rpm �Cqa -ql -qf -qc -qd -qi
-qa 查看系统上已经安装的软件包
# rpm -qa |more /*可以结合grep查找某软件包是否已安装 grub2-2.02-0.16.el7.centos.x86_64 centos-release-7-1.1503.el7.centos.2.8.x86_64 lvm2-2.02.115-3.el7.x86_64 filesystem-3.2-18.el7.x86_64 audit-2.4.1-5.el7.x86_64 ncurses-base-5.9-13.20130511.el7.noarch tuned-2.4.1-1.el7.noarch linux-firmware-20140911-0.1.git365e80c.el7.noarch aic94xx-firmware-30-6.el7.noarch glibc-common-2.17-78.el7.x86_64 openssh-server-6.6.1p1-11.el7.x86_64 |
-ql 查看安装后软件包中文件(可执行的二进制文件,配置文件,帮助文件,库文件…)展开后所在目录
# rpm -ql lrzsz-0.12.20-36.el7.x86_64 /usr/bin/rb /usr/bin/rx /usr/bin/rz /usr/bin/sb /usr/bin/sx /usr/bin/sz /usr/share/locale/de/LC_MESSAGES/lrzsz.mo /usr/share/man/man1/rz.1.gz /usr/share/man/man1/sz.1.gz |
-qf 通过此命令反查相关文件(可执行的二进制文件,配置文件,帮助文件,库文件…),是由哪个软件包生成
# rpm -qf /usr/bin/sz lrzsz-0.12.20-36.el7.x86_64
# rpm -qf /usr/share/locale/de/LC_MESSAGES/lrzsz.mo lrzsz-0.12.20-36.el7.x86_64
# rpm -qf /usr/bin/sb lrzsz-0.12.20-36.el7.x86_64 |
-qi 软件包的简介(软件包的功能,作者,许可…)
# rpm -qi vim-common-7.2.411-1.8.el6.i686 Name : vim-common Relocations: (not relocatable) Version : 7.2.411 Vendor: Red Hat, Inc. Release : 1.8.el6 Build Date: 2012年02月17日 星期五 23时24分04秒 Install Date: 2015年01月10日 星期六 22时44分25秒 Build Host: x86-012.build.bos.redhat.com Group : Applications/Editors Source RPM: vim-7.2.411-1.8.el6.src.rpm Size : 17772584 License: Vim and GPLv2+ and BSD and LGPLv2+ and Open Publication Signature : RSA/8, 2012年04月05日 星期四 13时42分54秒, Key ID 199e2f91fd431d51 Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> URL : http://www.vim.org/ Summary : The common files needed by any version of the VIM editor Description : VIM (VIsual editor iMproved) is an updated and improved version of the vi editor. Vi was the first real screen-based editor for UNIX, and is still very popular. VIM improves on vi by adding new features: multiple windows, multi-level undo, block highlighting and more. The vim-common package contains files which every VIM binary will need in order to run.
If you are installing vim-enhanced or vim-X11, you'll also need to install the vim-common package. |
-qc 软件包的文本文件配置通常在/etc目录下(有些软件没有配置文件)
# rpm -qc vim-common-7.2.411-1.8.el6.i686 /etc/vimrc |
-qd 软件包的安装后生成的文档(帮助文档居多)
# rpm -qd vim-common-7.2.411-1.8.el6.i686 /usr/share/doc/vim-common-7.2.411/Changelog.rpm /usr/share/doc/vim-common-7.2.411/LICENSE /usr/share/doc/vim-common-7.2.411/README.txt /usr/share/doc/vim-common-7.2.411/README_ami.txt /usr/share/doc/vim-common-7.2.411/README_amibin.txt /usr/share/doc/vim-common-7.2.411/README_amisrc.txt /usr/share/doc/vim-common-7.2.411/README_bindos.txt /usr/share/doc/vim-common-7.2.411/README_dos.txt /usr/share/doc/vim-common-7.2.411/README_extra.txt …………………………………. /usr/share/man/pl/man1/xxd.1.gz /usr/share/man/ru/man1/evim.1.gz /usr/share/man/ru/man1/ex.1.gz /usr/share/man/ru/man1/rview.1.gz /usr/share/man/ru/man1/rvim.1.gz /usr/share/man/ru/man1/view.1.gz /usr/share/man/ru/man1/vim.1.gz /usr/share/man/ru/man1/vimdiff.1.gz /usr/share/man/ru/man1/vimtutor.1.gz /usr/share/man/ru/man1/xxd.1.gz |
# rpm --checksig httpd-2.2.15-26.el6.i686.rpm httpd-2.2.15-26.el6.i686.rpm: RSA sha1 ((MD5) PGP) md5 NOT OK (MISSING KEYS: (MD5) PGP#fd431d51) |
常用的选项 rpm �Ce 软件包名
-e
--nodeps在卸载之前不做依赖检查(慎用).