rpm命令是RPM軟件包的管理工具。rpm原本是Red Hat Linux發行版專門用來管理Linux各項套件的程序,由於它遵循GPL規則且功能強大方便,因而廣受歡迎。逐漸受到其他發行版的採用。RPM套件管理方式的出現,讓Linux易於安裝,升級,間接提升了Linux的適用度。
常見用法:
用法: rpm [選項...]
-a:查詢所有套件;
-b<完成階段><套件檔>+或-t <完成階段><套件檔>+:設置包裝套件的完成階段,並指定套件檔的文件名稱;
-c:只列出組態配置文件,本參數需配合"-l"參數使用;
-d:只列出文本文件,本參數需配合"-l"參數使用;
-e<套件檔>或--erase<套件檔>:刪除指定的套件;
-f<文件>+:查詢擁有指定文件的套件;
-h或--hash:套件安裝時列出標記;
-i:顯示套件的相關信息;
-i<套件檔>或--install<套件檔>:安裝指定的套件檔;
-l:顯示套件的文件列表;
-p<套件檔>+:查詢指定的RPM套件檔;
-q:使用詢問模式,當遇到任何問題時,rpm指令會先詢問用戶;
-R:顯示套件的關聯性信息;
-s:顯示文件狀態,本參數需配合"-l"參數使用;
-U<套件檔>或--upgrade<套件檔>:升級指定的套件檔;
-v:顯示指令執行過程;
-vv:詳細顯示指令執行過程,便於排錯。
對照幫助文檔:
[root@rhel7_node2 ~]# rpm --help
Usage: rpm [OPTION...] 用法:rpm【選項】
Query/Verify package selection options:查詢/驗證 包 選擇 選項
-a, --all query/verify all packages
-f, --file query/verify package(s) owning file
-g, --group query/verify package(s) in group
-p, --package query/verify a package file
--pkgid query/verify package(s) with package
identifier
--hdrid query/verify package(s) with header
identifier
--triggeredby query the package(s) triggered by the
package
--whatrequires query/verify the package(s) which require a
dependency
--whatprovides query/verify the package(s) which provide a
dependency
--nomanifest do not process non-package files as
manifests
Query options (with -q or --query):
-c, --configfiles list all configuration files
-d, --docfiles list all documentation files
-L, --licensefiles list all license files
--dump dump basic file information
-l, --list list files in package
--queryformat=QUERYFORMAT use the following query format
-s, --state display the states of the listed files
Verify options (with -V or --verify):
--nofiledigest don't verify digest of files
--nofiles don't verify files in package
--nodeps don't verify package dependencies
--noscript don't execute verify script(s)
Install/Upgrade/Erase options:
--allfiles install all files, even configurations
which might otherwise be skipped
--allmatches remove all packages which match <package>
(normally an error is generated if
<package> specified multiple packages)
--badreloc relocate files in non-relocatable package
-e, --erase=<package>+ erase (uninstall) package
--excludedocs do not install documentation
--excludepath=<path> skip files with leading component <path>
--force short hand for --replacepkgs --replacefiles
-F, --freshen=<packagefile>+ upgrade package(s) if already installed
-h, --hash print hash marks as package installs (good
with -v)
--ignorearch don't verify package architecture
--ignoreos don't verify package operating system
--ignoresize don't check disk space before installing
-i, --install install package(s)
--justdb update the database, but do not modify the
filesystem
--nodeps do not verify package dependencies
--nofiledigest don't verify digest of files
--nocontexts don't install file security contexts
--noorder do not reorder package installation to
satisfy dependencies
--noscripts do not execute package scriptlet(s)
--notriggers do not execute any scriptlet(s) triggered
by this package
--nocollections do not perform any collection actions
--oldpackage upgrade to an old version of the package
(--force on upgrades does this
automatically)
--percent print percentages as package installs
--prefix=<dir> relocate the package to <dir>, if
relocatable
--relocate=<old>=<new> relocate files from path <old> to <new>
--replacefiles ignore file conflicts between packages
--replacepkgs reinstall if the package is already present
--test don't install, but tell if it would work or
not
-U, --upgrade=<packagefile>+ upgrade package(s)
--reinstall=<packagefile>+ reinstall package(s)
Common options for all rpm modes and executables:
-D, --define='MACRO EXPR' define MACRO with value EXPR
--undefine=MACRO undefine MACRO
-E, --eval='EXPR' print macro expansion of EXPR
--macros=<FILE:...> read <FILE:...> instead of default file(s)
--noplugins don't enable any plugins
--nodigest don't verify package digest(s)
--nosignature don't verify package signature(s)
--rcfile=<FILE:...> read <FILE:...> instead of default file(s)
-r, --root=ROOT use ROOT as top level directory (default:
"/")
--dbpath=DIRECTORY use database in DIRECTORY
--querytags display known query tags
--showrc display final rpmrc and macro configuration
--quiet provide less detailed output
-v, --verbose provide more detailed output
--version print the version of rpm being used
Options implemented via popt alias/exec:
--scripts list install/erase scriptlets from
package(s)
--setperms set permissions of files in a package
--setugids set user/group ownership of files in a
package
--conflicts list capabilities this package conflicts
with
--obsoletes list other packages removed by installing
this package
--provides list capabilities that this package provides
--requires list capabilities required by package(s)
--info list descriptive information from package(s)
--changelog list change logs for this package
--xml list metadata in xml
--triggers list trigger scriptlets from package(s)
--last list package(s) by install time, most
recent first
--dupes list duplicated packages
--filesbypkg list all files from each package
--fileclass list file names with classes
--filecolor list file names with colors
--fscontext list file names with security context from
file system
--fileprovide list file names with provides
--filerequire list file names with requires
--filecaps list file names with POSIX1.e capabilities
Help options:
-?, --help Show this help message
--usage Display brief usage message
用法舉例:
如何安裝rpm軟件包
rpm -ivh your-package # 直接安裝
rpm --force -ivh your-package.rpm # 忽略報錯,強制安裝
如何卸載rpm軟件包:
[root@localhost ~]# rpm -ql tree # 查詢
[root@localhost ~]# rpm -e tree # 卸載
[root@localhost ~]# rpm -ql tree # 查詢
列出所有安裝過的包:
[root@localhost ~]# rpm -qa
如何獲得某個軟件包的文件全名:
[root@localhost ~]# rpm -q tree
rpm包中的文件安裝的位置:
[root@localhost ~]# rpm -ql tree # rpm -ql 包名
哪個軟件包包含這個程序:
rpm -qf `which 程序名` #返回軟件包的全名
rpm -qif `which 程序名` #返回軟件包的有關信息
rpm -qlf `which 程序名` #返回軟件包的文件列表[root@localhost ~]# rpm -qf `which sshd`