Linux RPM和YUM包管理完全指南(1)(8)
寻找 RPM
我们在前面看到 YUM 提供了搜索功能,可以搜索包描述和包名。如果需要查明哪个包包含某个还没有安装的程序,还有几种方法:
如果通过系统工具无法找到某个 RPM,可以通过 Rpmfind.Net 服务器寻找 RPM。
命令未找到
如果 Bash shell 搜索一个命令,但是没有找到,那么 shell 就搜索 shell 函数 command_not_found_handle。如果 command_not_found_handle 函数存在,shell 以原来的命令和参数作为参数调用它,函数的退出状态成为 shell 的退出状态。如果没有定义此函数,shell 输出错误消息并返回退出状态 127。常常在系统 /etc/bash.bashrc 文件中设置此函数。清单 27 说明如何搜索 command-not-found 功能并安装它。
清单 27. 寻找并安装 command-not-found 功能
[root@echidna ~]# yum search command-not-found Loaded plugins: presto, refresh-packagekit ========================== Matched: command-not-found ========================== PackageKit-command-not-found.x86_64 : Ask the user to install command line : programs automatically You have new mail in /var/spool/mail/root [root@echidna ~]# yum install PackageKit-command-not-found.x86_64 Loaded plugins: presto, refresh-packagekit Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package PackageKit-command-not-found.x86_64 0:0.5.7-2.fc12 set to be updated --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: PackageKit-command-not-found x86_64 0.5.7-2.fc12 updates 102 k Transaction Summary ================================================================================ Install 1 Package(s) Upgrade 0 Package(s) Total download size: 102 k Installed size: 262 k Is this ok [y/N]: y Downloading Packages: Setting up and reading Presto delta metadata Processing delta metadata Package(s) data still to download: 102 k PackageKit-command-not-found-0.5.7-2.fc12.x86_64.rpm | 102 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : PackageKit-command-not-found-0.5.7-2.fc12.x86_64 1/1 Installed: PackageKit-command-not-found.x86_64 0:0.5.7-2.fc12 Complete! |
清单 28 说明在安装 PackageKit-command-not-found 之后如何定义这个函数。如果函数无法执行搜索,那么它模拟标准的系统行为,返回 127。
清单 28. command_not_found_handle
[ian@echidna ~]$ type command_not_found_handle command_not_found_handle is a function command_not_found_handle () { runcnf=1; retval=127; [ ! -S /var/run/dbus/system_bus_socket ] && runcnf=0; [ ! -x /usr/sbin/packagekitd ] && runcnf=0; if [ $runcnf -eq 1 ]; then /usr/libexec/pk-command-not-found $1; retval=$?; else echo "bash: $1: command not found"; fi; return $retval } |
如果在 清单 1 中运行 gcl 之前安装了这个功能,可能会看到清单 29 所示的输出。
清单 29. 安装 command_not_found_handle 之后尝试运行 gcl
[ian@echidna ~]$ gcl Command not found. Install package 'gcl' to provide command 'gcl'? [N/y] |
其他工具
除了 yum 和 rpm 之外,发行商可能提供了用于从存储库安装包或更新整个系统的其他工具。这些工具可能是图形化工具或命令行工具,或者同时提供这两种界面。例如:
通常,这些工具以自动或半自动方式处理多个包更新。它们还可能提供显示存储库内容或搜索包的功能。更多信息参见发行版的文档。
PackageKit
讨论包安装就不能不提到 PackageKit,这是一个为更方便地安装和更新软件而设计的系统。它的意图是把不同发行版中使用的所有软件图形化工具统一起来。PackageKit 使用一个由系统激活的守护进程,这意味着这个守护进程只在需要时激活。Packagekit 有适用于 Gnome (gnome-packagekit) 和 KDE (KPackageKit) 的版本。上面介绍的 command-not-found 功能也是 PackageKit 的组成部分。它包括命令 pkcon从控制台执行包管理功能)和 pkmon监视包集活动)。它还包含用于添加软件包或更新系统的图形化工具。图 1 给出 Software Update 图形界面的示例。
图 1. Fedora 12 (Gnome) 上的 Software Update 图形界面
除了这里讨论的内容,RPM 和 YUM 包管理系统还有许多特性。本文介绍就到这里为止,想要更加深入的了解,可以参考其他的文章和资料。
评论暂时关闭