APT HOWTO-第五章 获取软件包信息

类别:软件工程 点击:0 评论:0 推荐:
 APT HOWTO
第五章 获取软件包信息

有些基于APT系统的前端程序,能十分方便地获得系统软件包列表,列表包括可安装或已安装的软件包,还可以显示某软件包属于哪个域(section),它的优先级(priority)是多少,它的说明文档,等等。

但是...在此我们想的学习如何使用APT本身来完成。你如何找出你想要安装的软件包的名称?

我们完成这个任务的方法有很多。我们从apt-cache开始,APT系统使用这个程序来维护它的数据库。下面我们通过一些实际操作来对它做个概览。



5.1 获得软件包名称
==================
假设你十分怀念玩Atari 2600的好日子,你决定用APT安装一个Atari emulator,随后再下载几个游戏,你可以这样:

[root]@[/] # apt-cache search atari
atari-fdisk-cross - Partition editor for Atari (running on non-Atari)
circuslinux - The clowns are trying to pop balloons to score points!
madbomber - A Kaboom! clone
tcs - Character set translator.
atari800 - Atari emulator for svgalib/X/curses
stella - Atari 2600 Emulator for X windows
xmess-x - X binaries for Multi-Emulator Super System

我们找到了几个相关的软件包,以及有关的简单描述。想进一步获得某个软件包的详细信息,你可以运行:

[root]@[/] # apt-cache show stella
Package: stella
Priority: extra
Section: non-free/otherosfs
Installed-Size: 830
Maintainer: Tom Lear <[email protected]>
Architecture: i386
Version: 1.1-2
Depends: libc6 (>= 2.1), libstdc++2.10, xlib6g (>= 3.3.5-1)
Filename: dists/potato/non-free/binary-i386/otherosfs/stella_1.1-2.deb
Size: 483430
MD5sum: 11b3e86a41a60fa1c4b334dd96c1d4b5
Description: Atari 2600 Emulator for X windows
Stella is a portable emulator of the old Atari 2600 video-game console
written in C++. You can play most Atari 2600 games with it. The latest
news, code and binaries for Stella can be found at:
http://www4.ncsu.edu/~bwmott/2600

屏幕上显示出这个软件包的详细信息及其用途的完整描述。如果你的系统中已安装了某个软件包而系统又搜索到它的新版本,系统会将它们的详细信息一并列出。如下例:

[root]@[/] # apt-cache show lilo
Package: lilo
Priority: important
Section: base
Installed-Size: 271
Maintainer: Russell Coker <[email protected]>
Architecture: i386
Version: 1:21.7-3
Depends: libc6 (>= 2.2.1-2), debconf (>=0.2.26), logrotate
Suggests: lilo-doc
Conflicts: manpages (<<1.29-3)
Filename: pool/main/l/lilo/lilo_21.7-3_i386.deb
Size: 143052
MD5sum: 63fe29b5317fe34ed8ec3ae955f8270e
Description: LInux LOader - The Classic OS loader can load Linux and others
This Package contains lilo (the installer) and boot-record-images to
install Linux, OS/2, DOS and generic Boot Sectors of other OSes.
.
You can use Lilo to manage your Master Boot Record (with a simple text screen)
or call Lilo from other Boot-Loaders to jump-start the Linux kernel.

Package: lilo
Status: install ok installed
Priority: important
Section: base
Installed-Size: 190
Maintainer: Vincent Renardias <[email protected]>
Version: 1:21.4.3-2
Depends: libc6 (>= 2.1.2)
Recommends: mbr
Suggests: lilo-doc
Description: LInux LOader - The Classic OS loader can load Linux and others
This Package contains lilo (the installer) and boot-record-images to
install Linux, OS/2, DOS and generic Boot Sectors of other OSes.
.
You can use Lilo to manage your Master Boot Record (with a simple text screen)
or call Lilo from other Boot-Loaders to jump-start the Linux kernel.

注意,首先列出的是可用软件包,接着列出的是已安装软件包。获取某个软件包的常规信息可运行:

[root]@[/] # apt-cache showpkg penguin-command
Package: penguin-command
Versions:
1.4.5-1(/var/lib/apt/lists/download.sourceforge.net_debian_dists_unstable_main_binary-i386_Packages)(/var/lib/dpkg/status)

Reverse Depends:
Dependencies:
1.4.5-1 - libc6 (2 2.2.1-2) libpng2 (0 (null)) libsdl-mixer1.1 (2 1.1.0) libsdl1.1 (0 (null)) zlib1g (2 1:1.1.3)
Provides:
1.4.5-1 -
Reverse Provides:

如果仅想了解某软件包的与哪些软件包关联,可运行:

[root]@[/] # apt-cache depends penguin-command
penguin-command
Depends: libc6
Depends: libpng2
Depends: libsdl-mixer1.1
Depends: libsdl1.1
Depends: zlib1g

总之,有一系列工具可帮助我们找到我们想要的软件包。



5.2 使用dpkg查找软件包名称
==========================
另一个定位软件包的方法是知道软件包中某个关键文件的名称。例如,你编译时需要某个头文件,查找提供该文件的软件包,你可以运行:

[root]@[/] # dpkg -S stdio.h
libc6-dev: /usr/include/stdio.h
libc6-dev: /usr/include/bits/stdio.h
perl: /usr/lib/perl/5.6.0/CORE/nostdio.h

或者:

[root]@[/] # dpkg -S /usr/include/stdio.h
libc6-dev: /usr/include/stdio.h

在清理硬盘空间时,了解系统中已安装软件的软件包名称十分有用,你可以运行:

[root]@[/] # dpkg -l | grep mozilla
ii mozilla-browse 0.9.6-7 Mozilla Web Browser

这个命令的缺点是它会“截断”软件包的名字。在上例中,软件包的全称是mozilla-browser,解决这个问题可以使用COLUMNS环境变量:

[kov]@[couve] $ COLUMNS=132 dpkg -l | grep mozilla
ii mozilla-browser 0.9.6-7 Mozilla Web Browser - core and browser

或显示成这样:

[root]@[/] # apt-cache search "Mozilla Web Browser"
mozilla-browser - Mozilla Web Browser



5.3 如何“按需”安装软件包
==========================
你正在编译某段程序,突然,停住了!一条错误信息报告说你没有它需要的头文件。让auto-apt来救你吧,它问你是否要安装需要的软件包,然后挂起编译进程,安装好软件包后再恢复编译进程。

你所要做的仅仅是:

auto-apt run command

这里“command”指在运行过程中可能出现“需求文件不存在”问题的命令。例如:

auto-apt run ./configure

一会儿,它就会告诉你要安装所需的软件包并自动转到apt-get处理。如果你正在运行X,就会一个图形界面提示窗口。

为了提高效率auto-apt所用的数据库需要实时更新。可调用auto-apt update,auto-apt updatedb和auto-apt update-local来完成更新。



5.4 如何知道文件属于哪个软件包
==============================
如果你想安装某个软件包,但用apt-cache查不出它的名称,不过你知道这个程序的文件名,或这个软件包中某些文件的文件名,那么你可以用apt-file来查找软件包名称。

$ apt-file search filename

它用起来很象dpkg -S,不过它还会列出包含该文件的已删除软件包。它也可以用来查找哪个软件包包含编译时所缺的文件,当然,解决这类问题auto-apt可能是更好的方案,请参阅 5.3如何“按需”安装软件包。

用这个命令,你可以列出软件包的内容:

$ apt-file list packagename

apt-file用一个数据库来存放所有软件包的内容信息,和auto-apt一样,这个数据库也需要实时更新,完成更新可以运行:

# apt-file update

默认情况下,apt-file和auto-apt使用同一个数据库,参阅 5.3如何“按需”安装软件包。



5.5 如何掌握软件包的变化情况
============================
在每个软件包被安装以后,都会在文档目录(/usr/share/doc/packagename)生成一个changelog.Debian.gz的文件,这个文件记录了该软件包最后一次更新对系统做了哪些修改,你可以用zless阅读这些信息。不过当你对整个系统进行升级以后,逐个查看软件包的更新信息可不是件容易事。

有一个工具能帮你完成这项任务,它就是apt-listchanges。首先你要装上apt-listchanges软件包。在安装的过程中,Debconf会问你一些问题,按你的要求回答它们就行了。

“Should apt-listchanges be automatically run by apt”(想让apt自动运行apt-listchanges吗?)这个选项非常有用,因为在你使用apt更新软件包时,它会告诉你此次软件包更新将会对原有系统做出了哪些修改,你分析了这些信息以后再决定是否执行此次更新。“Should apt-listchanges prompt for confirmation after displaying changes?”(显示更新信息后,需要apt-listchanges等待你的确认信息吗?)选项也非常有用,因为在你阅读完更新信息后,它会询问你是否继续安装进程,如果你不想继续,apt-listchanges会返回一条错误信息,告诉apt停止安装进程。

安装了apt-listchanges后,每当apt下载软件包时(不论来源是Internet、光盘或是硬盘)都会显示这些软件包的系统更新信息。

本文地址:http://com.8s8s.com/it/it33030.htm