entOS下rpm命令详解

entOS下rpm命令详解

CentOS下rpm命令详解

通用选项

-v 显示附加信息

-vv 显示调试信息

--root 让RPM将指定的路径做为"根目录",这样预安装程序和后安
装程序都会安装到这个目录下 --dbpath 设置RPM 资料库存所在的路径为

查询

[root@localhost tmp]#rpm -q tree
tree-1.5.3-3.el6.x86_64 #PKG为包全名
rpm -q PKG
[root@localhost Packages]#rpm -qf /bin/ls
coreutils-8.4-43.el6.x86_64 rpm -qf /PATH/TO/FILE
[root@localhost Packages]#rpm -q --changelog tree
* Thu Nov 27 2014 Tim Waugh <[email protected]> - 1.5.3-3
- Handle large UID/GID values (bug #1110559). * Wed Mar 03 2010 Tim Waugh <[email protected]> 1.5.3-2
- Added comments to all patches.
... rpm -q --changelog PKG
[root@localhost Packages]#rpm -qi tree
Name : tree Relocations: (not relocatable)
Version : 1.5.3 Vendor: CentOS
Release : 3.el6 Build Date: Wed 14 Jan 2015 08:21:02 PM CST
Install Date: Sat 25 Mar 2017 04:17:05 AM CST Build Host: c6b9.bsys.dev.centos.org
Group : Applications/File Source RPM: tree-1.5.3-3.el6.src.rpm
... rpm -qi PKG
[root@localhost Packages]#rpm -ql tree
/usr/bin/tree
/usr/share/doc/tree-1.5.3
/usr/share/doc/tree-1.5.3/LICENSE
/usr/share/doc/tree-1.5.3/README
/usr/share/man/man1/tree.1.gz rpm -ql PKG
[root@localhost Packages]#rpm -qd tree
/usr/share/doc/tree-1.5.3/LICENSE
/usr/share/doc/tree-1.5.3/README
/usr/share/man/man1/tree.1.gz rpm -qd PKG
[root@localhost Packages]#rpm -qc bash
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc rpm -qc PKG
[root@localhost Packages]#rpm -q --scripts bash
postinstall scriptlet (using <lua>):
bashfound = false;
shfound = false; f = io.open("/etc/shells", "r");
if f == nil
then
... #有四个时间点可以执行脚本程序:包安装前、安装后、卸载前以及卸载后

安装

[root@localhost Packages]#rpm -ivh gcc-   ## 按两次tab键
gcc-4.4.7-17.el6.x86_64.rpm gcc-java-4.4.7-17.el6.x86_64.rpm
gcc-c++-4.4.7-17.el6.x86_64.rpm gcc-objc-4.4.7-17.el6.x86_64.rpm
gcc-gfortran-4.4.7-17.el6.x86_64.rpm gcc-objc++-4.4.7-17.el6.x86_64.rpm
gcc-gnat-4.4.7-17.el6.x86_64.rpm
#安装
[root@localhost Packages]#rpm -ivh gcc-4.4.7-17.el6.x86_64.rpm #/PATH/TO/PKG为rpm包的路径
rpm -ivh /PATH/TO/PKG
[root@localhost Packages]#rpm -ivh --noscripts tree-1.5.3-3.el6.x86_64.rpm
warning: tree-1.5.3-3.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:tree ########################################### [100%] rpm -ivh --noscripts PKG
[root@localhost Packages]#rpm -ivh --replacepkgs tree-1.5.3-3.el6.x86_64.rpm
warning: tree-1.5.3-3.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:tree ########################################### [100%] rpm -ivh --replacepkgs PKG
-h安装时以#显示安装进度
--percent以百分比的形式输出安装的进度
--test测试安装
--replacepkgs替换属于其它软件包的文件
--force忽略软件包及文件的冲突
--noscripts不运行预安装和后安装脚本
--ignorearch不校验软件包的结构
--ignoreos不检查软件包运行的操作系统
--nodeps不检查依赖性关系

卸载

[root@localhost Packages]#rpm -e gcc

rpm -e PKG
[root@localhost Packages]#rpm -e --noscripts tree

rpm -e --noscripts PKG

升级

[root@localhost Packages]#rpm -Uvh tree-1.5.3-3.el6.x86_64.rpm

rpm -Uvh PKG

rpm -Fvh PKG
05-02 07:51