如何使用RPM命令(示例)

RPM代表“ Redhat Package Manager”,它是用于基于RHEL / CentOS的操作系统的命令行软件包管理工具。您可以使用RPM命令安装,卸载,更新,查询和验证软件包。该工具仅适用于以.rpm格式构建的软件包。RPM命令只能安装指定的软件包,不能安装该软件包所需的依赖项。

在本教程中,我们将通过一些示例向您展示如何使用RPM软件包管理器。

先决条件

  • 运行CentOS,RHEL或Fedora的服务器。
  • 在您的服务器上配置了root密码。

基本语法

RPM命令的基本语法如下所示:

rpm [OPTION] [PACKAGENAME]

您可以使用以下命令,使用RPM命令列出所有可用选项:

rpm --help

您应该看到以下屏幕:

RPM帮助

使用RPM安装,更新和删除软件包

在安装任何RPM软件包之前,您可以使用以下命令列出该软件包的依赖性:

rpm -qpR epel-release-latest-8.noarch.rpm

输出:

warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
config(epel-release) = 8-7.el8
redhat-release >= 8
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(PayloadIsXz) <= 5.2-1

您还可以使用以下命令获取该软件包的信息:

rpm -qip epel-release-latest-8.noarch.rpm

输出:

warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
Name        : epel-release
Version     : 8
Release     : 7.el8
Architecture: noarch
Install Date: (not installed)
Group       : System Environment/Base
Size        : 30269
License     : GPLv2
Signature   : RSA/SHA256, Thursday 10 October 2019 12:19:30 PM EDT, Key ID 21ea45ab2f86d6a1
Source RPM  : epel-release-8-7.el8.src.rpm
Build Date  : Thursday 10 October 2019 12:16:18 PM EDT
Build Host  : buildvm-04.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : http://download.fedoraproject.org/pub/epel
Bug URL     : https://bugz.fedoraproject.org/epel-release
Summary     : Extra Packages for Enterprise Linux repository configuration
Description :
This package contains the Extra Packages for Enterprise Linux (EPEL) repository
GPG key as well as configuration for yum.

您可以使用以下命令安装此软件包:

rpm -ivh epel-release-latest-8.noarch.rpm

输出:

warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:epel-release-8-7.el8             ################################# [100%]

您可以使用以下命令安装任何无依赖的RPM软件包:

rpm -ivh --nodeps epel-release-latest-8.noarch.rpm

要更新已安装的RPM软件包,请运行以下命令:

rpm -Uvh epel-release-latest-8.noarch.rpm

输出:

warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
	package epel-release-8-7.el8.noarch is already installed

要删除已安装的RPM软件包,请运行以下命令:

rpm -ev epel-release

输出:

正在准备软件包...
epel-release-8-7.el8.noarch

使用RPM显示包装信息

要显示任何软件包的详细信息,请运行以下命令:

rpm -ql epel-release

输出:

/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-optional.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean

您可以使用以下命令找到任何软件包的配置文件:

rpm -qc httpd

输出:

/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-optional.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/ etc / httpd / conf / magic
/etc/logrotate.d/httpd
/ etc / sysconfig / htcacheclean

您可以使用以下命令显示有关任何软件包的更多信息:

rpm -qi httpd

输出:

Name        : httpd
Version     : 2.4.37
Release     : 16.module_el8.1.0+256+ae790463
Architecture: x86_64
Install Date: Thursday 23 January 2020 11:48:36 PM EST
Group       : System Environment/Daemons
Size        : 5611291
License     : ASL 2.0
Signature   : RSA/SHA256, Monday 23 December 2019 05:22:02 PM EST, Key ID 05b555b38483c65d
Source RPM  : httpd-2.4.37-16.module_el8.1.0+256+ae790463.src.rpm
Build Date  : Monday 23 December 2019 03:46:30 PM EST
Build Host  : x86-02.mbox.centos.org
Relocations : (not relocatable)
Packager    : CentOS Buildsys <bugs@centos.org>
Vendor      : CentOS
URL         : https://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

使用以下命令从目录或文件中查找软件包:

rpm -qf /etc/NetworkManager/

输出:

NetworkManager-1.14.0-14.el8.x86_64
dhcp-client-4.3.6-30.el8.x86_64

使用RPM验证软件包

使用以下命令在安装任何软件包之前对其进行验证:

rpm -Vp epel-release-latest-8.noarch.rpm

输出:

warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY

要验证所有已安装的rpm软件包,请运行以下命令:

rpm -Va

输出:

.......T.  c /etc/kdump.conf
.M.......  g /var/lib/plymouth/boot-duration
.M.......  g /var/cache/dnf/packages.db
.....UG..  g /var/lib/sss/mc/group
.....UG..  g /var/lib/sss/mc/initgroups
.....UG..  g /var/lib/sss/mc/passwd
.M.......  c /etc/rc.d/rc.local
.M.......  c /etc/machine-id

使用RPM检查有关已安装软件包的信息

使用以下命令验证是否已安装任何软件包:

要验证已安装的软件包,请运行以下命令:

rpm -q epel-release

如果已安装指定的软件包,则应该看到以下输出:

epel-release-8-7.el8.noarch

要验证未安装的软件包,请运行以下命令:

rpm -q mysql-server

您应该获得以下输出:

package mysql-server is not installed

要列出系统中安装的所有软件包,请运行以下命令:

rpm -qa

输出:

dos2unix-7.4.0-3.el8.x86_64
platform-python-pip-9.0.3-13.el8.noarch
geolite2-country-20180605-1.el8.noarch
symlinks-1.4-19.el8.x86_64
python3-six-1.11.0-8.el8.noarch
fontpackages-filesystem-1.44-22.el8.noarch
rootfiles-8.1-22.el8.noarch
polkit-0.115-6.el8.x86_64
xkeyboard-config-2.24-3.el8.noarch
iwl6050-firmware-41.28.5.1-92.el8.1.noarch
libmodulemd1-1.8.0-5.el8.x86_64
pkgconf-m4-1.4.2-1.el8.noarch
iwl5000-firmware-8.83.5.1_1-92.el8.1.noarch
samba-common-4.9.1-8.el8.noarch
kbd-misc-2.0.4-8.el8.noarch

要按名称和大小列出所有已安装的软件包,请运行以下命令:

rpm -qa --queryformat '%{name} %{size}\n'

输出:

dos2unix 682042
platform-python-pip 7746190
geolite2-country 3424334
symlinks 19682
python3-six 100282
fontpackages-filesystem 0
rootfiles 599

使用RPM查找任何软件包的手册页

您可以运行以下命令来了解拥有文件或文件夹的软件包的文档列表。

rpm -qdf /etc/NetworkManager/

输出:

/usr/share/doc/NetworkManager/AUTHORS
/usr/share/doc/NetworkManager/CONTRIBUTING
/usr/share/doc/NetworkManager/NEWS
/usr/share/doc/NetworkManager/README
/usr/share/doc/NetworkManager/TODO
/usr/share/doc/NetworkManager/examples/server.conf
/usr/share/man/man1/nm-online.1.gz
/usr/share/man/man1/nmcli.1.gz
/usr/share/man/man5/NetworkManager.conf.5.gz
/usr/share/man/man5/nm-settings-ifcfg-rh.5.gz
/usr/share/man/man5/nm-settings-keyfile.5.gz
/usr/share/man/man5/nm-settings.5.gz
/usr/share/man/man5/nm-system-settings.conf.5.gz
/usr/share/man/man7/nmcli-examples.7.gz
/usr/share/man/man8/NetworkManager.8.gz
/usr/share/doc/dhcp-client/README.dhclient.d
/usr/share/doc/dhcp-client/dhclient-enter-hooks
/usr/share/doc/dhcp-client/dhclient.conf.example
/usr/share/doc/dhcp-client/dhclient6.conf.example
/usr/share/man/man5/dhclient.conf.5.gz
/usr/share/man/man5/dhclient.leases.5.gz
/usr/share/man/man8/dhclient-script.8.gz
/usr/share/man/man8/dhclient.8.gz

结论

在以上教程中,我们学习了如何在CentOS 8操作系统上使用RPM管理软件包。

原文:https://www.howtoforge.com/centos-redhat-rpm-command/


评论列表
 
 
发表评论
  • 发表评论

  • 为你推荐
    Ta的个人站点

    Ubar发布文章92篇

    与他人进行分享是一种快乐!当你的分享可以帮助到他们,会感觉更快乐!