当前位置:操作系统 > Unix/Linux >>

DebianAPTHOWTO第五章获取软件包信息

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 <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

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

  [root]@[/] # 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.

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

  [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

  默认情
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,