In addition to the package manager, we can also install through the rpm command; can all packages be installed through the rpm command? No, the file ends with a .rpm suffix; sometimes we find file.rpm on some websites, and we have to install it with rpm;
1) Initialize the rpm database;
query whether an rpm package is installed through the rpm command, but also to It is done through the rpm database; so we often use the following two commands to initialize the rpm database;
[root@localhost beinan]# rpm --initdb
[root@localhost beinan]# rpm --rebuilddb 注:这个要花好长时间;
Note: These two parameters are extremely useful. Sometimes there is a problem with the rpm system and cannot be installed and inquired. Most of the problems are here;
2) The query function of RPM package management:
command format
rpm {-q|--query} [select-options] [query-options]
The query function of RPM is extremely powerful and one of the most important functions; to give a few common examples, for more details, please refer to #man rpm
1. Querying the installed software in the system;
1) Query the installed software of the system;
语法:rpm -q 软件名
Example:
[root@localhost beinan]# rpm -q gaim
gaim-1.3.0-1.fc4
-q is --query, which means "ask" in Chinese. This command indicates whether gaim is installed in the system; if it is installed, it will output information; if it is not installed, it will output information that gaim is not installed;
To view all installed packages in the system, add the -a parameter;
[root@localhost RPMS]# rpm -qa
If paged view, add a pipe | and more command;
[root@localhost RPMS]# rpm -qa |more
Find a certain software in all installed packages, such as gaim; it can be extracted with grep;
[root@localhost RPMS]# rpm -qa |grep gaim
The function of the above is the same as the output of rpm -q gaim;
2) Query which software package an installed file belongs to;
语法 rpm -qf 文件名
Note: The absolute path where the file name is located should be pointed out
Example:
[root@localhost RPMS]# rpm -qf /usr/lib/libacl.la
libacl-devel-2.2.23-8
3) Query where the installed software packages are installed;
语法:rpm -ql 软件名 或 rpm rpmquery -ql 软件名
Example:
[root@localhost RPMS]# rpm -ql lynx
[root@localhost RPMS]# rpmquery -ql lynx
4) Query information about an installed package
语法格式: rpm -qi 软件名
Example:
[root@localhost RPMS]# rpm -qi lynx
5) Check the configuration file of the installed software;
语法格式:rpm -qc 软件名
Example:
[root@localhost RPMS]# rpm -qc lynx
6) View the documentation installation location of an installed software:
语法格式: rpm -qd 软件名
Example:
[root@localhost RPMS]# rpm -qd lynx
7) Check the software packages and files that the installed software depends on;
语法格式: rpm -qR 软件名
Example:
[root@localhost beinan]# rpm -qR rpm-python
Query the summary of installed software: For a package that has been installed, we can combine a series of parameters; such as rpm -qil; such as:
[root@localhost RPMS]# rpm -qil lynx
2、对于未安装的软件包的查看:
查看的前提是您有一个.rpm 的文件,也就是说对既有软件file.rpm的查看等;
1)查看一个软件包的用途、版本等信息;
语法: rpm -qpi file.rpm
举例:
[root@localhost RPMS]# rpm -qpi lynx-2.8.5-23.i386.rpm
2)查看一件软件包所包含的文件;
语法: rpm -qpl file.rpm
举例:
[root@localhost RPMS]# rpm -qpl lynx-2.8.5-23.i386.rpm
3)查看软件包的文档所在的位置;
语法: rpm -qpd file.rpm
举例:
[root@localhost RPMS]# rpm -qpd lynx-2.8.5-23.i386.rpm
5)查看一个软件包的配置文件;
语法: rpm -qpc file.rpm
举例:
[root@localhost RPMS]# rpm -qpc lynx-2.8.5-23.i386.rpm
4)查看一个软件包的依赖关系
语法: rpm -qpR file.rpm
举例:
[root@localhost archives]# rpm -qpR yumex_0.42-3.0.fc4_noarch.rpm
/bin/bash
/usr/bin/python
config(yumex) = 0.42-3.0.fc4
pygtk2
pygtk2-libglade
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
usermode
yum >= 2.3.2
三)软件包的安装、升级、删除等;
1、安装和升级一个rpm 包;
[root@localhost beinan]#rpm -vih file.rpm 注:这个是用来安装一个新的rpm 包;
[root@localhost beinan]#rpm -Uvh file.rpm 注:这是用来升级一个rpm 包;
如果有依赖关系的,请解决依赖关系,其实软件包管理器能很好的解决依赖关系,请看前面的软件包管理器的介绍;如果您在软件包管理器中也找不到依赖关系的包;那只能通过编译他所依赖的包来解决依赖关系,或者强制安装;
语法结构:
[root@localhost beinan]# rpm -ivh file.rpm --nodeps --force
[root@localhost beinan]# rpm -Uvh file.rpm --nodeps --force
更多的参数,请查看 man rpm
举例应用:
[root@localhost RPMS]# rpm -ivh lynx-2.8.5-23.i386.rpm
Preparing... ########################################### [100%]
1:lynx ########################################### [100%]
[root@localhost RPMS]# rpm -ivh --replacepkgs lynx-2.8.5-23.i386.rpm
Preparing... ########################################### [100%]
1:lynx ########################################### [100%]
注: --replacepkgs 参数是以已安装的软件再安装一次;有时没有太大的必要;
测试安装参数 --test ,用来检查依赖关系;并不是真正的安装;
[root@localhost RPMS]# rpm -ivh --test gaim-1.3.0-1.fc4.i386.rpm
Preparing... ########################################### [100%]
由新版本降级为旧版本,要加 --oldpackage 参数;
[root@localhost RPMS]# rpm -qa gaim
gaim-1.5.0-1.fc4
[root@localhost RPMS]# rpm -Uvh --oldpackage gaim-1.3.0-1.fc4.i386.rpm
Preparing... ########################################### [100%]
1:gaim ########################################### [100%]
[root@localhost RPMS]# rpm -qa gaim
gaim-1.3.0-1.fc4
为软件包指定安装目录:要加 -relocate 参数;下面的举例是把gaim-1.3.0-1.fc4.i386.rpm指定安装在 /opt/gaim 目录中;
[root@localhost RPMS]# rpm -ivh --relocate /=/opt/gaim gaim-1.3.0-1.fc4.i386.rpm
Preparing... ########################################### [100%]
1:gaim ########################################### [100%]
[root@localhost RPMS]# ls /opt/
gaim
为软件包指定安装目录:要加 -relocate 参数;下面的举例是把lynx-2.8.5-23.i386.rpm 指定安装在 /opt/lynx 目录中;
[root@localhost RPMS]# rpm -ivh --relocate /=/opt/lynx --badreloc lynx-2.8.5-23.i386.rpm
Preparing... ########################################### [100%]
1:lynx ########################################### [100%]
我们安装在指定目录中的程序如何调用呢?一般执行程序,都放在安装目录的bin或者sbin目录中;看下面的例子;如果有错误输出,就做相应的链接,用 ln -s ;
[root@localhost RPMS]# /opt/lynx/usr/bin/lynx
Configuration file /etc/lynx.cfg is not available.
[root@localhost RPMS]# ln -s /opt/lynx/etc/lynx.cfg /etc/lynx.cfg
[root@localhost RPMS]# /opt/lynx/usr/bin/lynx www.linuxsir.org
2、删除一个rpm 包;
首先您要学会查询rpm 包 ;请看前面的说明;
[root@localhost beinan]#rpm -e 软件包名
举例:我想移除lynx 包,完整的操作应该是:
[root@localhost RPMS]# rpm -e lynx
如果有依赖关系,您也可以用--nodeps 忽略依赖的检查来删除。但尽可能不要这么做,最好用软件包管理器 systerm-config-packages 来删除或者添加软件;
[root@localhost beinan]# rpm -e lynx --nodeps