Linux RPM命令以及有关CentOS,RedHat和Fedora的示例

What is Rpm? Rpm is package manager popular in Red Hat-based operating systems.   Rpm full name is Red Hat Package Manager. Rpm uses rpm as package extension and format. Rpm packages are generally distributed from repositories on the internet but using USB, optical media or other ways is popular too in the old days. Yum is the online package manager used to get rpm packages from network or internet repositories.

什么是RPM? Rpm是在基于Red Hat的操作系统中流行的软件包管理器。 Rpm的全名是Red Hat Package Manager。 Rpm使用rpm作为软件包的扩展名和格式。 Rpm软件包通常是从Internet上的存储库分发的,但是在过去也很流行使用USB,光学介质或其他方式。 Yum是在线软件包管理器,用于从网络或Internet存储库获取rpm软件包。

描述 (Description)

Yum files are named like below with name, version, release, architecture.

百胜文件的命名如下,包括名称,版本,发行版,体系结构。

<name>-<version>-<release>.<architecture>.rpm

储存库 (Repositories)

As stated before repositories are used to hold rpm packages on the internet but also a CD can be used as a repository in rare situations. Repositories are used but yum/dnf commands.

如前所述,存储库用于将rpm软件包保存在Internet上,但在极少数情况下,CD也可以用作存储库。 使用存储库,但使用yum / dnf命令。

转速搜索 (Rpm Search)

Generally, Rpm packages are provided by repository and package managers like yum, dnf. But there are alternative sites that provide Rpm packages download manually.

通常,RPM软件包由存储库和软件包管理器(如yum,dnf)提供。 但是,还有其他站点可以提供手动下载的Rpm软件包。

http://rpm.pbone.net/

http://rpm.pbone.net/

转速 (Srpm)

Source code of packages is distributed with srpm packages. Srpm packages are zipped with tar.gz or tar.bz2

软件包的源代码与srpm软件包一起分发。 使用tar.gz或tar.bz2压缩Srpm软件包

PatchRPM和DeltaRpm(PatchRPM and DeltaRpm)

Rpm packages provide some options to makes the download size smaller. Packages include a lot of different type of files. But not all files are changed. To makes packages smaller only changed files are distributed in Deltarpm’s.

Rpm软件包提供了一些选项来减小下载大小。 软件包包括许多不同类型的文件。 但并非所有文件都被更改。 为了使软件包更小,只有更改过的文件才分发到Deltarpm中。

Rpm安装 (Rpm Install)

Rpm packages have generally dependencies which means if we want to install some package we need to install other related packages before installing it. But We skip this and install some package with -ivh parameters.

Rpm软件包通常具有依赖性,这意味着如果我们要安装某些软件包,则需要在安装之前安装其他相关软件包。 但是我们跳过此步骤,并使用-ivh参数安装一些软件包。

$ rpm -ivh tmux-1.8-4.el7.x86_64.rpm
Rpm Install
Rpm Install
Rpm安装

We need root privileges to install the rpm package. In our example, we tried to install tmux but as we see in message it is installed already.

我们需要root特权才能安装rpm软件包。 在我们的示例中,我们尝试安装tmux,但是正如我们在消息中看到的那样,它已经安装。

LEARN MORE  How To Remove Packages From Ubuntu, Debian, Mint and Kali with Apt-Get Uninstall Command with Examples
了解更多信息如何使用Apt-Get Uninstall命令和示例从Ubuntu,Debian,Mint和Kali中删除软件包

检查依赖(Check Dependency)

As we know Rpm packages have dependencies which mean to install a package other packages may be needed. The needed packages must be installed before installing the current package. We can check dependencies like below.

我们知道Rpm软件包具有依赖性,这意味着要安装软件包,可能需要其他软件包。 在安装当前软件包之前,必须先安装所需的软件包。 我们可以像下面检查依赖项。

rpm -qpR tmux-1.8-4.el7.x86_64.rpm
Rpm dependency check
RPM依赖检查

As we see tmux package depends on sh, standard C library, ncurses, Event library, etc.

正如我们看到的,tmux包依赖于sh,标准C库,ncurses,事件库等。

安装忽略依赖性检查 (Install Ignoring Dependency-Check)

Normally if we try to install a package which has unmet dependency it will give error and do not installed.  There is a way to install packages with unmet dependencies with forcefully. We will provide --nodepsoption for installation.

通常,如果我们尝试安装依赖关系未满足的软件包,则会出现错误,并且不会安装。 有一种方法可以强制安装具有未满足的依赖关系的软件包。 我们将提供--nodeps选项进行安装。

$ rpm -ivh --nodeps tmux-1.8-4.el7.x86_64.rpm
Install Omitting Dependency Check
Install Omitting Dependency-Check
安装省略依赖性检查

下载Rpm(Download Rpm)

Yum is used to downloading and installing automatically but in some cases, we may need to download package and install another system or etc. We can download an rpm package with a command named yumdownloader like below. yumdownloader do not need any privilege for download operation.

Yum用于自动下载和安装,但是在某些情况下,我们可能需要下载软件包并安装另一个系统等。我们可以使用名为yumdownloader的命令下载rpm软件包,如下所示。 yumdownloader不需要任何特权即可进行下载操作。

$ yumdownloader tmux
Download Rpm
Download Rpm
下载Rpm

We only provide a package name to the yumdownloader.

我们仅向yumdownloader提供软件包名称。

检查已安装的RPM软件包 (Check Installed RPM Package)

Rpm database holds information about installed packages. we can query this database like below. If the Rpm/application is installed the full package name is printed.

Rpm数据库包含有关已安装软件包的信息。 我们可以如下查询该数据库。 如果安装了Rpm /应用程序,则会打印完整的软件包名称。

$ rpm -q tmux
Check Installed RPM Package
Check Installed RPM Package
检查已安装的RPM软件包

列出已安装的RPM软件包的所有文件(List All Files Of Installed RPM Package)

We may need to list files of and installed Rpm package. It is very similar to the checking process we will just add an -lparameter like below.

我们可能需要列出Rpm软件包和已安装的软件包的文件。 这与检查过程非常相似,我们将仅添加如下所示的-l参数。

$ rpm -ql tmux
List files of installed packages
列出已安装软件包的文件

列出最近安装的RPM软件包(List Recently Installed RPM Packages)

We may want to list lastly installed Rpm packages. But keep in mind that will generate a lot of lines.

我们可能要列出最近安装的Rpm软件包。 但是请记住,这将产生很多线条。

$ rpm -qa --last

I cannot put a screenshot here because it exceeds my terminal history. So I can put some limit or pagination to this list.

我无法在此处放置屏幕截图,因为它超出了我的终端历史记录。 因此,我可以对此列表进行一些限制或分页。

$ rpm -qa --last | less
List Recently Installed RPM Packages
List Recently Installed RPM Packages
列出最近安装的RPM软件包

As we can this will print the date of the RPM package installation with time information. In the screenshot for example kdeadmin package installed 24 November at 09:50:33 .

我们将尽可能打印出带有时间信息的RPM软件包安装日期。 在示例屏幕快照中, kdeadmin软件包示例于11月24日09:50:33安装。

LEARN MORE  Yum Command Tutorial With Examples For Linux Package Management Like Install, Update Remove
了解更多Yum命令教程,并提供Linux软件包管理示例,例如安装,更新,删除

列出所有已安装的RPM软件包(List All Installed RPM Packages)

Another way to list installed packages is to listing all packages not just latest installed.

列出已安装软件包的另一种方法是列出所有软件包,而不仅仅是最新安装的软件包。

$ rpm -qa

Using less in this situation is more practical. We can also search for command output with less.

在这种情况下减少使用更为实用。 我们也可以搜索更少的命令输出。

$ rpm -qa | less
List Recently Installed RPM Packages
List Recently Installed RPM Packages
列出最近安装的RPM软件包

升级RPM软件包(Upgrade RPM Packages)

If an Rpm package is all ready installed we can upgrade existing package to a newer one. Advantage of the upgrade is that after upgrade old package is also held as a backup and if the new package does not work old package can be used.

如果一个Rpm软件包已准备就绪,我们可以将现有软件包升级到一个较新的软件包。 升级的优势在于,升级后,旧软件包也将作为备份,如果新软件包不起作用,则可以使用旧软件包。

rpm -Uvh tmux-1.8-4.el7.x86_64.rpm
Upgrade RPM Packages
Upgrade RPM Packages
升级RPM软件包

卸载RPM软件包(Uninstall RPM Package)

Uninstalling or erasing and Rpm package can be done with -e parameter like below.

可以使用-e参数(如下所示)来完成卸载或擦除Rpm软件包的操作。

$ rpm -evv tmux-1.8-4.el7.x86_64.rpm
Uninstall RPM Package
Uninstall RPM Package
卸载RPM软件包

不受依赖地卸载RPM软件包(Uninstall RPM Package Without Dependencies)

We can only uninstall package itself and hold dependency packages in the system.

我们只能卸载软件包本身,并在系统中保留依赖软件包。

$ rpm -ev --nodeps tmux
Uninstall RPM Package Without Dependencies
Uninstall RPM Package Without Dependencies
不受依赖地卸载RPM软件包

An alternative way to remove Rpm package is not erasing dependencies.

删除Rpm软件包的另一种方法是不删除依赖项。

查询文件名以找到相关的RPM软件包 (Query File Name To Find Related RPM Package)

Sometimes we need to find related Rpm package from a file name.

有时我们需要从文件名中找到相关的Rpm软件包。

rpm -qf /bin/sh
Query File Name To Find Related RPM Package
Query File Name To Find Related RPM Package
查询文件名以找到相关的RPM软件包

获取有关已安装的RPM软件包的信息(Get Info About Installed RPM Package)

We can get information about and installed Rpm package like name version, release, size, url, etc.

我们可以获取有关并安装Rpm软件包的信息,例如名称版本,发行版,大小,URL等。

$ rpm -qi bash
Get Info About Installed RPM Package
Get Info About Installed RPM Package
获取有关已安装的RPM软件包的信息

获取有关RPM软件包的信息(Get Information About RPM Package)

Actually Rpm provides a lot of important information about packages and its content. We can list and Rpm package information without installing it.

实际上,RPM提供了许多有关软件包及其内容的重要信息。 我们可以列出和Rpm软件包信息,而无需安装它。

$ rpm -qip tmux-1.8-4.el7.x86_64.rpm
Get Information About RPM Package
Get Information About RPM Package
获取有关RPM软件包的信息

查询已安装的RPM软件包的文档(Query Documentation Of Installed RPM Package)

Documentation of an installed Rpm package can get like below. It is similar to finding Rpm package name from a file.

已安装的Rpm软件包的文档如下所示。 这类似于从文件中查找Rpm软件包名称。

$ rpm -qdf /bin/bash
Query Documentation Of Installed RPM Package
Query Documentation Of Installed RPM Package
查询已安装的RPM软件包的文档

验证RPM软件包(Verify RPM Package)

We can check and Rpm package and verify against the Rpm database. to verify -Vp parameters should be provided.

我们可以检查Rpm包并对照Rpm数据库进行验证。 验证是否应提供-Vp参数。

$ rpm -Vp tmux-1.8-4.el7.x86_64.rpm
Verify RPM Package
Verify RPM Package
验证RPM软件包

验证所有RPM软件包(Verify All RPM Packages)

We can verify all installed Rpm packages. Verify process will look into the Rpm database to complete this job. Keep in mind that this will require a lot of time. We will use -a or --all for this operation.

我们可以验证所有已安装的Rpm软件包。 验证过程将调查Rpm数据库以完成此作业。 请记住,这将需要很多时间。 我们将使用-a--all进行此操作。

$ rpm -Va
Verify All RPM Packages
Verify All RPM Packages
验证所有RPM软件包

导入RPM包的GPG密钥(Import GPG Key Of RPM Package)

GPG is a security protocol to verify authenticity. GPG is used recently to eliminate rouge repositories and Rpm packages but to benefit from this protocol GPG must be configured for Rpm. To configure GPG signs must be imported.

GPG是用于验证真实性的安全协议。 GPG最近用于消除大量存储库和Rpm软件包,但要从该协议中受益,必须为Rpm配置GPG。 要配置GPG,必须导入标志。

$ rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

列出所有导入的RPM GPG密钥 (List All Imported RPM GPG Keys)

We can list existing or imported GPG keys like below.

我们可以像下面列出现有或导入的GPG密钥。

$ rpm -qa gpg-pubkey*
List All Imported RPM GPG Keys
List All Imported RPM GPG Keys
列出所有导入的RPM GPG密钥

As we can see from the screenshot that GPG keys have a different naming convention like gpg-pubkey-GUID where GUID or UID is a unique identifier to prevent name collision.

从屏幕快照中可以看到,GPG密钥具有不同的命名约定,例如gpg-pubkey-GUID ,其中GUIDUID是防止名称冲突的唯一标识符。

LEARN MORE  10 Things To Do After Fedora Installation
了解更多Fedora安装后要做的10件事

初始化RPM数据库(Initialize RPM Database)

If we want to create a new RPM database which will hold installed package information we can use the --initdb option. This will create a new, empty, fresh database.

如果我们要创建一个新的RPM数据库来保存已安装的软件包信息,则可以使用--initdb选项。 这将创建一个新的,空的,新鲜的数据库。

$ sudo rpm --initdb

重建损坏的RPM数据库 (Rebuild Corrupted RPM Database)

Some time Rpm database can be get corrupted. Corrupted Rpm database can not be updated or used. So to get it into working condition Rpm database should be rebuilt like below.

有时Rpm数据库可能会损坏。 损坏的Rpm数据库无法更新或使用。 因此,要使其进入工作状态,应按如下所示重建Rpm数据库。

$ cd /var/lib
$ rm __db*
$ rpm --rebuilddb
$ rpmdb_verify Packages

Here we go the /var/liband remove uncomplete database packages. Then run rpm rebuild command.

在这里,我们进入/var/lib并删除不完整的数据库包。 然后运行rpm rebuild命令。

翻译自: https://www.poftut.com/linux-rpm-command-with-examples/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值