Home >System Tutorial >LINUX >How to install, update and uninstall RPM software packages under Linux

How to install, update and uninstall RPM software packages under Linux

王林
王林forward
2024-01-07 15:26:241520browse

Under the Linux operating system, almost all software is installed, uninstalled and managed through RPM. The full name of RPM is Redhat Package Manager, which is a software proposed by Redhat Company for managing software packages under Linux. When installing Linux, except for a few core modules, almost all other modules are installed through RPM. RPM has five operating modes: installation, uninstallation, upgrade, query and verification.

RPM installation operation

Order:
rpm -i package file name to be installed
Examples are as follows:

rpm -i example.rpm 安装 example.rpm 包;
rpm -iv example.rpm 安装 example.rpm 包并在安装过程中显示正在安装的文件信息;
rpm -ivh example.rpm 安装 example.rpm 包并在安装过程中显示正在安装的文件信息及安装进度;

RPM Query Operation

Order:
rpm -q …
Additional query command:

a Query all installed packages The following two additional commands are used to query installation package information;
i displays the installation package information;
l Display the directories to which all files in the installation package are installed;
s displays the status of all files in the installation version and the directories where they are installed; the following two additional commands are used to specify whether the installation package or the installed file needs to be queried;
p queries the installation package information;
f queries the information of a certain installed file;

Examples are as follows:

rpm -qa | grep tomcat4 查看 tomcat4 是否被安装;
rpm -qip example.rpm 查看 example.rpm 安装包的信息;
rpm -qif /bin/df 查看/bin/df 文件所在安装包的信息;
rpm -qlf /bin/df 查看/bin/df 文件所在安装包中的各个文件分别被安装到哪个目录下;

RPM uninstall operation

Order:
rpm -e Installation package that needs to be uninstalled
Before uninstalling, you usually need to use the rpm -q... command to find out the name of the installation package that needs to be uninstalled.
Examples are as follows:
rpm -e tomcat4 Uninstall tomcat4 package

RPM upgrade operation

Order:
rpm -U Packages that need to be upgraded

Examples are as follows:
rpm -Uvh example.rpm Upgrade example.rpm package
RPM Verification Operation
Order:
rpm -V Packages that need to be verified

Examples are as follows:
rpm -Vf /etc/tomcat4/tomcat4.conf
The output information is similar to the following:
S.5....T c /etc/tomcat4/tomcat4.conf
Among them, S indicates that the file size has been modified, and T indicates that the file date has been modified. Due to space limitations, for more verification information, please refer to the rpm help file: man rpm

Other additional commands for RPM

--force forced operations such as forced installation, deletion, etc.;
--requires displays the dependencies of this package;
--nodeps Ignore dependencies and continue;

The rpm command is a management tool for RPM software packages. rpm was originally a program used by the Red Hat Linux distribution to manage various Linux packages. It is very popular because it follows GPL rules and is powerful and convenient. Gradually adopted by other distributions. The emergence of RPM package management method makes Linux easy to install and upgrade, which indirectly improves the applicability of Linux.

grammar

rpm(选项)(参数)

Options

-a:查询所有套件;
-b6536afa81333a4f1f76f8c9001203bf098e14ff7a6416e291ad9e94e3d4343ac+或-t 6536afa81333a4f1f76f8c9001203bf098e14ff7a6416e291ad9e94e3d4343ac+:设置包装套件的完成阶段,并指定套件档的文件名称;
-c:只列出组态配置文件,本参数需配合"-l"参数使用;
-d:只列出文本文件,本参数需配合"-l"参数使用;
-e98e14ff7a6416e291ad9e94e3d4343ac或--erase98e14ff7a6416e291ad9e94e3d4343ac:删除指定的套件;
-f70120f5feaf4a4e4f18aa0e9e4edf7f7+:查询拥有指定文件的套件;
-h或--hash:套件安装时列出标记;
-i:显示套件的相关信息;
-i98e14ff7a6416e291ad9e94e3d4343ac或--<span class="wp_keywordlink"><a href="https://www.php.cn/link/5ca41a86596a5ed567d15af0be224952" rel="nofollow" target="_blank">install</a></span>98e14ff7a6416e291ad9e94e3d4343ac:安装指定的套件档;
-l:显示套件的文件列表;
-p98e14ff7a6416e291ad9e94e3d4343ac+:查询指定的RPM套件档;
-q:使用询问模式,当遇到任何问题时,rpm指令会先询问用户;
-R:显示套件的关联性信息;
-s:显示文件状态,本参数需配合"-l"参数使用;
-U98e14ff7a6416e291ad9e94e3d4343ac或--upgrade98e14ff7a6416e291ad9e94e3d4343ac:升级指定的套件档;
-v:显示指令执行过程;
-vv:详细显示指令执行过程,便于排错。

parameter

Software package: Specify the rpm package to be manipulated.

Example

How to install rpm package

Installation of rpm software packages can be done using the program rpm. Execute the following command:

rpm -ivh your-package.rpm

Where your-package.rpm is the file name of the rpm package you want to install, usually placed in the current directory.

The following warnings or prompts may appear during the installation process:

... conflict with ...

It may be that there are some files in the package to be installed that may overwrite existing files. By default, such a situation cannot be installed correctly. You can use rpm --force -i to force the installation. Can

... is needed by ...
... is not installed ...

If you have not installed some software required by this package, you can use rpm --nodeps -i to ignore this information, which means rpm -i --force --nodeps is OK. Ignoring all dependencies and file issues, any package can be installed, but such forced installation of software packages cannot guarantee full functionality.

How to install the .src.rpm package

Some software packages end with .src.rpm. This type of software package is an rpm package containing source code and needs to be compiled during installation. There are two installation methods for this type of software package:

method one:

rpm -i your-package.src.rpm
<span class="wp_keywordlink"><a href="https://www.php.cn/link/01632f7b7a127233fa1188bd6c2e42e1" rel="nofollow" target="_blank">cd</a></span> /usr/src/redhat/SPECS
<span class="wp_keywordlink"><a href="https://www.php.cn/link/a2c770e3cc20139f429ebfe6e8cdea0b" rel="nofollow" target="_blank">rpmbuild</a></span> -bp your-package.specs<span style="color: #808080"> #一个和你的软件包同名的specs文件</span>
cd /usr/src/redhat/BUILD/your-package/<span style="color: #808080">#一个和你的软件包同名的目录</span>
./configure <span style="color: #808080">#这一步和编译普通的源码软件一样,可以加上参数</span>
<span class="wp_keywordlink"><a href="https://www.php.cn/link/03dadd644cb5856e1bb2c75dda01a4f0" rel="nofollow" target="_blank">make</a></span>
make install

Method Two:

rpm -i you-package.src.rpm
cd /usr/src/redhat/SPECS

The first two steps are the same as method 1

rpmbuild -bb your-package.specs #一个和你的软件包同名的specs文件

At this time, there is a new rpm package in /usr/src/redhat/RPM/i386/ (depending on the specific package, it may be i686, noarch, etc.). , this is a compiled binary file.

Execute rpm -i new-package.rpm to complete the installation.

How to uninstall rpm package

Use the command rpm -ePackage name. The package name can contain version number and other information, but it cannot have the suffix .rpm. For example, to uninstall the software package proftpd-1.2.8-1, you can use the following format:

rpm -e proftpd-1.2.8-1
rpm -e proftpd-1.2.8
rpm -e proftpd-
rpm -e proftpd

cannot be in the following format:

rpm -e proftpd-1.2.8-1.i386.rpm
rpm -e proftpd-1.2.8-1.i386
rpm -e proftpd-1.2
rpm -e proftpd-1

Sometimes some errors or warnings may appear:

... is needed by ...

This means that this software is needed by other software and cannot be uninstalled casually. You can use rpm -e --nodeps to force uninstall

How to get the files in the rpm package without installing it

Using toolsrpm2cpio and cpio

rpm2cpio xxx.rpm | cpio -<span class="wp_keywordlink"><a href="https://www.php.cn/link/a8621fdfb85b64f3214f86af1e1504a2" rel="nofollow" target="_blank">vi</a></span>
rpm2cpio xxx.rpm | cpio -idmv
rpm2cpio xxx.rpm | cpio --extract --make-directories

参数i和extract相同,表示提取文件。v表示指示执行进程,d和make-directory相同,表示根据包中文件原来的路径建立目录,m表示保持文件的更新时间。

如何查看与rpm包相关的文件和其他信息

下面所有的例子都假设使用软件包mysql-3.23.54a-11

1、我的系统中安装了那些rpm软件包。

rpm -qa 讲列出所有安装过的包

如果要查找所有安装过的包含某个字符串sql的软件包

rpm -qa | <span class="wp_keywordlink"><a href="https://www.php.cn/link/c467978aaae44a0e8054e174bc0da4bb" rel="nofollow" target="_blank">grep</a></span> sql

2、如何获得某个软件包的文件全名。

rpm -q mysql

可以获得系统中安装的mysql软件包全名,从中可以获得当前软件包的版本等信息。这个例子中可以得到信息mysql-3.23.54a-11

3、一个rpm包中的文件安装到那里去了?

rpm -ql 包名

注意这里的是不包括.rpm后缀的软件包的名称,也就是说只能用mysql或者mysql-3.23.54a-11而不是mysql-3.23.54a-11.rpm。如果只是想知道可执行程序放到那里去了,也可以用which,比如:

which mysql

4、一个rpm包中包含那些文件。

  • 一个没有安装过的软件包,使用rpm -qlp ****.rpm
  • 一个已经安装过的软件包,还可以使用rpm -ql ****.rpm

5、如何获取关于一个软件包的版本,用途等相关信息?

  • 一个没有安装过的软件包,使用rpm -qip ****.rpm
  • 一个已经安装过的软件包,还可以使用rpm -qi ****.rpm

6、某个程序是哪个软件包安装的,或者哪个软件包包含这个程序。

rpm -qf `which 程序名`<span style="color: #808080">#返回软件包的全名</span>
rpm -qif `which 程序名` <span style="color: #808080">#返回软件包的有关信息</span>
rpm -qlf `which 程序名` <span style="color: #808080">#返回软件包的文件列表</span>

注意,这里不是引号,而是`,就是键盘左上角的那个键。也可以使用rpm -qilf,同时输出软件包信息和文件列表。

7、某个文件是哪个软件包安装的,或者哪个软件包包含这个文件。

注意,前一个问题中的方法,只适用与可执行的程序,而下面的方法,不仅可以用于可执行程序,也可以用于普通的任何文件。前提是知道这个文件名。首先获得这个程序的完整路径,可以用whereis或者which,然后使用rpm -qf例如:

<span style="color: #ff0000">whereis <span class="wp_keywordlink"><a href="https://www.php.cn/link/96fca94df72984fc97ee5095410d4dec" rel="nofollow" target="_blank">ftptop</a></span></span>
ftptop: /usr/bin/ftptop /usr/share/<span class="wp_keywordlink"><a href="https://www.php.cn/link/432fd02f951f393df1591310e6811118" rel="nofollow" target="_blank">man</a></span>/man1/ftptop.1.gz

<span style="color: #ff0000">rpm -qf /usr/bin/ftptop</span>
proftpd-1.2.8-1

<span style="color: #ff0000">rpm -qf /usr/share/doc/proftpd-1.2.8/rfc/rfc0959.txt</span>
proftpd-1.2.8-1

The above is the detailed content of How to install, update and uninstall RPM software packages under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete