有些基于APT系统的前端程序,能十分方便地获得系统软件包列表,列表包括可安 装或已安装的软件包,还可以显示某软件包属于哪个section,它的优先级是多少, 它的说明文档等等。
但是...在此我们想的学习如何使用APT本身来完成。你如何找出你想要安装的软件 包的名称?
我们完成这个任务的方法有很多。我们从apt-cache开始,APT系统使用 这个程序来维护它的数据库。下面我们通过一些实际操作来对它做个概览。
假设你十分怀念玩Atari 2600的好日子,你决定用APT安装一个Atari emulator, 随后再下载几个游戏,你可以这样:
# 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
我们找到了几个相关的软件包,以及有关的简单描述。想进一步获得某个软件包的 详细信息,你可以运行:
# apt-cache show stella
Package: stella
Priority: extra
Section: non-free/otherosfs
Installed-Size: 830
Maintainer: Tom Lear <tom@trap.mtview.ca.us>
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
屏幕上显示出这个软件包的详细信息及其用途的完整描述。如果你的系统中已安装 了某个软件包而系统又搜索到它的新版本,系统会将它们的详细信息一并列出。如 下例:
# apt-cache show lilo
Package: lilo
Priority: important
Section: base
Installed-Size: 271
Maintainer: Russell Coker <russell@coker.com.au>
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 <vincent@debian.org>
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.
注意,首先列出的是可用软件包,接着列出的是已安装软件包。获取某个软件包的 常规信息可运行:
# 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:
如果仅想了解某软件包的与哪些软件包关联,可运行:
# apt-cache depends penguin-command
penguin-command
Depends: libc6
Depends: libpng2
Depends: libsdl-mixer1.1
Depends: libsdl1.1
Depends: zlib1g
总之,有一系列工具可帮助我们找到我们想要的软件包。
另一个定位软件包的方法是知道软件包中某个关键文件的名称。例如,你编译时需 要某个“.h”头文件,查找提供该文件的软件包,你可以运行:
# 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
或者:
# dpkg -S /usr/include/stdio.h
libc6-dev: /usr/include/stdio.h
解系统中已安装软件的软件包名称十分有用,譬如当你想清理硬盘空间时,可以运行:
# 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
或显示成这样:
# apt-cache search "Mozilla Web Browser"
mozilla-browser - Mozilla Web Browser
你正在编译某段程序,突然,停住了!一条错误信息报告说你没有它需要的.h头文件。让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来完成更新。
如果你想安装某个软件包,但用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 节。
在每个软件包被安装以后,都会在文档目录(/usr/share/doc/packagename) 生成一个changelog.Debian.gz的文件,这个文件记录了该软件包最后一 次更新对系统做了哪些修改,你可以用zless阅读这些信息。不过当你对 整个系统进行升级以后,逐个查看软件包的更新信息可不是件容易事。
有一个工具能帮你完成这项任务,它就是apt-listchanges。首先你
要装上apt-listchanges软件包。在安装的过程中,为了进行配
置,Debconf会问你一些问题,按你的要求回答它们就行了。
第一个问题是问你希望apt-listchanges如何来显示修改日志。你可以让它把信息
通过邮件的方式发送给你,这对于自动更新是非常有用的。或者你可以让它在less等程序中显示修改日志,这样在继续升级前你就可以查看它们了。如果
你不希望apt-listchanges在升级的时候自动的运行,可以
回答none。
安装了apt-listchanges后,每当apt下载软件包之后(不论来源是Internet、光盘 或是硬盘)都会显示这些软件包的系统更新信息。
APT HOWTO
1.8.10.4 - 2005年3月kov@debian.orgiamlyoo@163.com