APT 的很多方面都是可以定制的.事实上,在 /etc/apt/apt.conf 文件中, 您可以修改大多数命令行选项的默认值.
配置参数使用 名称 - 值 对,根据用途被分为几组. 组名在参数前边用 "::" 分割.tt apt.conf(5) 联机手册有相关语法介绍.
其它项目在对应命令的联机手册中有所描述(如 tt apt.get(1) 和 tt apt-cache(1) ). 比如:
APT::Default-Release "testing";
//在使用混合系统时, 设定默认下载的版本
APT::Get::Assume-Yes "true";
//如果在安装/卸载过程中出现询问, 应答为 y
如果在使用aptitude、apt-get 或 dpkg 时出现如下错误
E: Dynamic MMap ran out of room
可以在apt.conf中加入:
APT::Cache-Limit "12500000";
以重新设定缓存区大小.
访问资源库需要代理, 则可以加入类似下边的内容:
Acquire::http::proxy "http://user:pass@xxx.xxx.xxx.xxx:port";
Acquire::ftp::proxy "ftp://user:pass@xxx.xxx.xxx.xxx:port";
APT还提供了三个钩子程序, 用于在 dpkg 阶段调用.它们分别是 Pre-Invoke, Post-Invoke, Pre-Install-Pkgs.
DPkg::Pre-Invoke {"mount -o remount,rw /usr";};
DPkg::Post-Invoke {"mount -o remount,ro /usr";};
DPkg::Pre-Install-Pkgs {"dpkg-preconfigure --apt --priority=low --frontend=dialog";};
/usr/share/doc/apt/examples/apt.conf, /usr/share/doc/apt/examples/configure-index.gz 中给出详细的例子, 可以用于参照.
5. 安装
当发出安装请求时,apt 会根据其优化算法, 求解出最佳安装方案, 来完成用户的请求. 比如:
debian:~# apt-get install xchat
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
defoma fontconfig libatk1.0-0 libfontconfig1 libgtk2.0-0 libgtk2.0-bin
libgtk2.0-common libpango1.0-0 libpango1.0-common libperl5.8 libtiff4
libx11-6 libxcursor1 libxext6 libxft2 libxi6 libxrandr2 libxrender1 tcl8.4
ttf-bitstream-vera xchat-common xfree86-common xlibs-data
Suggested packages:
defoma-doc psfontmgr x-ttcidfont-conf dfontmgr ttf-kochi-gothic
ttf-kochi-mincho ttf-thryomanes ttf-baekmuk ttf-arphic-gbsn00lp
ttf-arphic-bsmi00lp ttf-arphic-gkai00mp ttf-arphic-bkai00mp tclreadline
libnet-google-perl x-window-system-core x-window-system
Recommended packages:
libft-perl libatk1.0-data hicolor-icon-theme
The following NEW packages will be installed:
defoma fontconfig libatk1.0-0 libfontconfig1 libgtk2.0-0 libgtk2.0-bin
libgtk2.0-common libpango1.0-0 libpango1.0-common libperl5.8 libtiff4
libx11-6 libxcursor1 libxext6 libxft2 libxi6 libxrandr2 libxrender1 tcl8.4
ttf-bitstream-vera xchat xchat-common xfree86-common xlibs-data
0 upgraded, 24 newly installed, 0 to remove and 1 not upgraded.
Need to get 12.5MB of archives.
After unpacking 39.1MB of additional disk space will be used.
Do you want to continue? [Y/n]
APT 下载软件时是根据 /var/lib/apt/lists 下的 _Packages 文件, 来获取软件的详细定位的, 而这些 _Packages 文件是通过命令:
#apt-get update
命令从 sources.list 中声明的顺序从资源库中获取的. 这一命令将对 Packages 索引文件进行更新. 因此, 在安装软件前, 或在修改 sources.list 后, 应该进行 apt-get update 操作.
每天运行, 或经常运行这一命令, 是个良好的习惯. APT 同时会清除/var/lib/apt/lists 目录下没有在
/etc/apt/sources.list 中声明的资源文件. 如果你使用
--no-list-cleanup(APT::Get::List-Cleanup),APT 将会保留这些文件,如果您只是在
sources.list 中临时禁用一条资源, 这样还是比较方便的; 当再次启用这条资源时, 就不需要重复下载 APT 的资源文件了.
在安装的时候您可以通过使用 --print-uris 选项将这些信息输出到屏幕. 比如:
#apt-get install --print-uris nano-tiny
Reading Package Lists... Done
Building Dependency Tree... Done
The following NEW packages will be installed:
nano-tiny
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 87.8kB of archives.
After unpacking 123kB of additional disk space will be used.
'http://ftp.us.debian.org/debian/pool/main/n/nano/nano-tiny_1.2.4-5_i386.deb'
nano-tiny_1.2.4-5_i386.deb 87786 07794bf630d1a9dffdf85917a9e39968
如果你想安装某个软件包, 但用 apt-cache 查不出它的名称,不过你知道这个程序的文件名, 或这个软件包中某些文件的文件名,
那么你可以用 apt-file 来查找软件包名称. 这个工具由同名软件包提供. apt-file 事实上是一个 APT 软件库中提供的
Contents 文件的接口. 每个发行版都提供这样的文件, 包括了某个发行版所要安装的所有文件的列表. 在使用 apt-file 前,
需要首先获取用户要查询的 Contents 文件. 运行 apt-file update 将会这个文件下载到 /var/cache/apt
目录. 这样就可以使用 apt-file 查询这个文件了. apt-file 的主要用途是确定某个文件是由哪个软件包提供的.
$ apt-file search filename
用这个命令, 你可以列出软件包的内容:
$ apt-file list packagename
和 apt-get 一样, 这个数据库也需要实时更新, 完成更新可以运行:
# apt-file update
8. 卸载和清除
如果你不再使用某些软件包, 你可以用 APT 将其从系统中删除. 要删除软件包只需输入: apt-get remove package. 如下所示:
debian:~# apt-get remove vim
Reading Package Lists... Done
Building Dependency Tree... Done
The following packages will be REMOVED:
vim vim-common
0 upgraded, 0 newly installed, 2 to remove and 1 not upgraded.
Need to get 0B of archives.
After unpacking 15.1MB disk space will be freed.
Do you want to continue? [Y/n]
可以注意到, 在请求删除 vim 时, vim-common 也会同时卸载, 因为 APT 会关注那些与被删除的软件包有依赖关系的软件包.
使用 APT 删除一个软件包将会连带删除那些与该软件包有依赖关系的软件包. 但是它们的配置文件, 如果有的话, 会完好无损地保留在系统里.
如果想彻底删除这些包及其配置文件,运行:
debian:~# apt-get remove vim --purge
Reading Package Lists... Done
Building Dependency Tree... Done
The following packages will be REMOVED:
vim* vim-common*
0 upgraded, 0 newly installed, 2 to remove and 1 not upgraded.
Need to get 0B of archives.
After unpacking 15.1MB disk space will be freed.
Do you want to continue? [Y/n]
注意软件包后的星号, 这表示将要被清除, 而不是简单的删除.
您也可以在安装的同时进行软件卸载, 比如:
debian:~# apt-get install nano-tiny nano-
Reading Package Lists... Done
Building Dependency Tree... Done
The following packages will be REMOVED:
nano
The following NEW packages will be installed:
nano-tiny
0 upgraded, 1 newly installed, 1 to remove and 1 not upgraded.
Need to get 0B/87.8kB of archives.
After unpacking 913kB disk space will be freed.
Do you want to continue? [Y/n]
注意 nano 后边的 "-", 它提示在安装 nano-tiny 的同时将nano 卸载掉.
当然也可以用 dpkg 进行软件包删除, 但是它并不能自动解决依赖问题.
9. 系统升级
9.1 软件升级
不同的版本之间, 提供的软件包的数目, 以及软件包间的依赖关系会有很大差异, 如果更改新的版本, 比如将系统从 stable 升级到
testing, update/upgrade 不会安装没有在系统中出现的软件包; 只会对现存软件包进行升级.
并且如果现有软件新版本依赖关系发生而来变化, 那么将无法对其升级:
debian:~# apt-get upgrade
Reading Package Lists...
Building Dependency Tree...
The following packages have been kept back:
adduser apache apache-common apache2-utils apt apt-utils aptitude bc
...
The following packages will be upgraded:
base-files base-passwd bash binutils bitchx bootcd bootcd-i386 bsdmainutils
...
142 upgraded, 0 newly installed, 0 to remove and 83 not upgraded.
Need to get 51.8MB of archives.
After unpacking 12.5MB of additional disk space will be used.
Do you want to continue? [Y/n]
我们看到有些包被阻止更新(kept back), 现在我们就用使用APT的智能升级机制: apt-get dist-upgrade
debian:~# apt-get dist-upgrade
Reading Package Lists...
Building Dependency Tree...
The following packages will be REMOVED:
libgssapi1-heimdal libroken16-kerberos4kth libsp1 mysql-common-4.1
postfix-tls
The following NEW packages will be installed:
apache2-common apache2-mpm-prefork cpp-4.0 dmidecode gcc-4.0 gcc-4.0-base
...
The following packages will be upgraded:
adduser apache apache-common apache2-utils apt apt-utils aptitude base-files
...
225 upgraded, 42 newly installed, 5 to remove and 0 not upgraded.
Need to get 132MB of archives.
After unpacking 70.6MB of additional disk space will be used.
Do you want to continue? [Y/n]
当 apt-get dist-upgrade 时, APT 会安装新软件包,甚至会删除废弃的软件包. 实际的新软件包的安装, 或删除旧软件包, 仍是由 dpkg 完成的.