aptitude versus apt-get

本文对比了在Ubuntu系统中使用apt-get与aptitude进行软件包管理的区别。特别是在移除软件及其未使用的依赖方面,aptitude能更智能地清理不再需要的依赖项。

Important Update
Apparently the new version of apt-get in Edgy Eft (Ubuntu 6.10) has a function that allows you to remove unused dependencies when removing an application:
sudo apt-get autoremove applicationname

So the points outlined on this page about using aptitude over apt-get are largely irrelevant if you're using Edgy Eft (6.10), Feisty Fawn (7.04), or any future version of Ubuntu.

Information Relevant to Older Versions of Ubuntu
You may notice that many Ubuntu websites ask you to install software using the apt-get command. Others may use the aptitude command instead. In many ways, they're the same in that they both draw from the repositories in your /etc/apt/sources.list to retrieve and install software.

Below is the demonstrated difference, though, at least for Ubuntu 6.06 and earlier. The example displayed is the package kword, but it works the same for any package that has dependencies.

Both aptitude and apt-get will install kword and its dependencies (kspread, kword-data, and libwv2-1c2), but only aptitude will actually remove the dependencies when kword is removed (and only if no other packages depend on those dependencies).

Note: In order for aptitude to work properly, you must first do an update, then an install. Also, you cannot install with apt-get or Synaptic and then expect to have dependencies removed by uninstalling with aptitude.

If you were unfortunate enough to use apt-get, and you want to clean out some unused dependencies, you can install and use deborphan or the graphical frontend gtkorphan (now available in Dapper if you enable extra repositories). Naturally, you would install it this way:

sudo aptitude update
sudo aptitude install gtkorphan

On to the demonstrations...

Aptitude Demonstration:

username@ubuntu:~$ sudo aptitude update && sudo aptitude install kword
Password:
Reading package lists... Done
Building dependency tree... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
Get:1 http://security.ubuntu.com dapper-security Release.gpg [189B]
Get:2 http://archive.ubuntu.com dapper Release.gpg [189B]
Get:3 http://archive.ubuntu.com dapper-updates Release.gpg [189B]
Get:4 http://security.ubuntu.com dapper-security Release [27.0kB]
Get:5 http://archive.ubuntu.com dapper-backports Release.gpg [189B]
Hit http://archive.ubuntu.com dapper Release
Get:6 http://archive.ubuntu.com dapper-updates Release [27.0kB]
Ign http://packages.freecontrib.org dapper Release.gpg
Ign http://packages.freecontrib.org dapper Release
Get:7 http://archive.ubuntu.com dapper-backports Release [19.6kB]
Ign http://packages.freecontrib.org dapper/free Packages
Get:8 http://security.ubuntu.com dapper-security/main Packages [14.4kB]
Hit http://archive.ubuntu.com dapper/main Packages
Get:9 http://archive.ubuntu.com dapper/restricted Packages [4571B]
Hit http://archive.ubuntu.com dapper/main Sources
Get:10 http://archive.ubuntu.com dapper/restricted Sources [1478B]
Hit http://archive.ubuntu.com dapper/universe Packages
Hit http://archive.ubuntu.com dapper/universe Sources
Get:11 http://archive.ubuntu.com dapper/multiverse Packages [95.2kB]
Ign http://packages.freecontrib.org dapper/non-free Packages
Get:12 http://security.ubuntu.com dapper-security/restricted Packages [14B]
Get:13 http://security.ubuntu.com dapper-security/main Sources [3593B]
Get:14 http://security.ubuntu.com dapper-security/restricted Sources [14B]
Get:15 http://security.ubuntu.com dapper-security/universe Packages [3762B]
Get:16 http://security.ubuntu.com dapper-security/universe Sources [14B]
Ign http://packages.freecontrib.org dapper/free Sources
Ign http://packages.freecontrib.org dapper/non-free Sources
Get:17 http://archive.ubuntu.com dapper/multiverse Sources [46.6kB]
Hit http://packages.freecontrib.org dapper/free Packages
Get:18 http://archive.ubuntu.com dapper-updates/main Packages [10.2kB]
Get:19 http://archive.ubuntu.com dapper-updates/restricted Packages [14B]
Get:20 http://archive.ubuntu.com dapper-updates/main Sources [9006B]
Get:21 http://archive.ubuntu.com dapper-updates/restricted Sources [14B]
Get:22 http://archive.ubuntu.com dapper-backports/main Packages [14B]
Get:23 http://archive.ubuntu.com dapper-backports/restricted Packages [14B]
Get:24 http://archive.ubuntu.com dapper-backports/universe Packages [14B]
Get:25 http://archive.ubuntu.com dapper-backports/multiverse Packages [14B]
Hit http://packages.freecontrib.org dapper/non-free Packages
Hit http://packages.freecontrib.org dapper/free Sources
Hit http://packages.freecontrib.org dapper/non-free Sources
Fetched 263kB in 2s (89.0kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
The following NEW packages will be automatically installed:
kspread kword-data libwv2-1c2
The following NEW packages will be installed:
kspread kword kword-data libwv2-1c2
0 packages upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 6613kB of archives. After unpacking 18.9MB will be used.
Do you want to continue? [Y/n/?] y
Writing extended state information... Done
Get:1 http://archive.ubuntu.com dapper/main kspread 1:1.5.0-0ubuntu9 [2276kB]
Get:2 http://archive.ubuntu.com dapper/main libwv2-1c2 0.2.2-5 [225kB]
Get:3 http://archive.ubuntu.com dapper/main kword-data 1:1.5.0-0ubuntu9 [1590kB]
Get:4 http://archive.ubuntu.com dapper/main kword 1:1.5.0-0ubuntu9 [2522kB]
Fetched 6613kB in 45s (146kB/s)
Selecting previously deselected package kspread.
(Reading database ... 110852 files and directories currently installed.)
Unpacking kspread (from .../kspread_1%3a1.5.0-0ubuntu9_i386.deb) ...
Selecting previously deselected package libwv2-1c2.
Unpacking libwv2-1c2 (from .../libwv2-1c2_0.2.2-5_i386.deb) ...
Selecting previously deselected package kword-data.
Unpacking kword-data (from .../kword-data_1%3a1.5.0-0ubuntu9_all.deb) ...
Selecting previously deselected package kword.
Unpacking kword (from .../kword_1%3a1.5.0-0ubuntu9_i386.deb) ...
Setting up kspread (1.5.0-0ubuntu9) ...

Setting up libwv2-1c2 (0.2.2-5) ...

Setting up kword-data (1.5.0-0ubuntu9) ...

Setting up kword (1.5.0-0ubuntu9) ...

username@ubuntu:~$ sudo aptitude remove kword
Reading package lists... Done
Building dependency tree... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
The following packages are unused and will be REMOVED:
kspread kword-data libwv2-1c2
The following packages will be REMOVED:
kword
0 packages upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 18.9MB will be freed.
Do you want to continue? [Y/n/?] y
Writing extended state information... Done
(Reading database ... 111678 files and directories currently installed.)
Removing kword ...
Removing kspread ...
Removing kword-data ...
Removing libwv2-1c2 ...
username@ubuntu:~$

Apt-get Demonstration:

username@ubuntu:~$ sudo apt-get update && sudo apt-get install kword
Get:1 http://security.ubuntu.com dapper-security Release.gpg [189B]
Get:2 http://archive.ubuntu.com dapper Release.gpg [189B]
Get:3 http://archive.ubuntu.com dapper-updates Release.gpg [189B]
Get:4 http://archive.ubuntu.com dapper-backports Release.gpg [189B]
Hit http://security.ubuntu.com dapper-security Release
Hit http://archive.ubuntu.com dapper Release
Hit http://archive.ubuntu.com dapper-updates Release
Hit http://security.ubuntu.com dapper-security/main Packages
Hit http://archive.ubuntu.com dapper-backports Release
Hit http://archive.ubuntu.com dapper/main Packages
Hit http://archive.ubuntu.com dapper/restricted Packages
Hit http://archive.ubuntu.com dapper/main Sources
Ign http://packages.freecontrib.org dapper Release.gpg
Hit http://security.ubuntu.com dapper-security/restricted Packages
Hit http://security.ubuntu.com dapper-security/main Sources
Hit http://security.ubuntu.com dapper-security/restricted Sources
Hit http://archive.ubuntu.com dapper/restricted Sources
Hit http://archive.ubuntu.com dapper/universe Packages
Hit http://archive.ubuntu.com dapper/universe Sources
Hit http://archive.ubuntu.com dapper/multiverse Packages
Hit http://archive.ubuntu.com dapper/multiverse Sources
Ign http://packages.freecontrib.org dapper Release
Hit http://archive.ubuntu.com dapper-updates/main Packages
Hit http://archive.ubuntu.com dapper-updates/restricted Packages
Hit http://archive.ubuntu.com dapper-updates/main Sources
Hit http://archive.ubuntu.com dapper-updates/restricted Sources
Hit http://security.ubuntu.com dapper-security/universe Packages
Hit http://security.ubuntu.com dapper-security/universe Sources
Ign http://packages.freecontrib.org dapper/free Packages
Ign http://packages.freecontrib.org dapper/non-free Packages
Ign http://packages.freecontrib.org dapper/free Sources
Ign http://packages.freecontrib.org dapper/non-free Sources
Hit http://packages.freecontrib.org dapper/free Packages
Hit http://archive.ubuntu.com dapper-backports/main Packages
Hit http://packages.freecontrib.org dapper/non-free Packages
Hit http://packages.freecontrib.org dapper/free Sources
Hit http://archive.ubuntu.com dapper-backports/restricted Packages
Hit http://archive.ubuntu.com dapper-backports/universe Packages
Hit http://archive.ubuntu.com dapper-backports/multiverse Packages
Hit http://packages.freecontrib.org dapper/non-free Sources
Fetched 4B in 2s (2B/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
kspread kword-data libwv2-1c2
Suggested packages:
koffice-doc-html
The following NEW packages will be installed:
kspread kword kword-data libwv2-1c2
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/6613kB of archives.
After unpacking 18.9MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Selecting previously deselected package kspread.
(Reading database ... 110852 files and directories currently installed.)
Unpacking kspread (from .../kspread_1%3a1.5.0-0ubuntu9_i386.deb) ...
Selecting previously deselected package libwv2-1c2.
Unpacking libwv2-1c2 (from .../libwv2-1c2_0.2.2-5_i386.deb) ...
Selecting previously deselected package kword-data.
Unpacking kword-data (from .../kword-data_1%3a1.5.0-0ubuntu9_all.deb) ...
Selecting previously deselected package kword.
Unpacking kword (from .../kword_1%3a1.5.0-0ubuntu9_i386.deb) ...
Setting up kspread (1.5.0-0ubuntu9) ...

Setting up libwv2-1c2 (0.2.2-5) ...

Setting up kword-data (1.5.0-0ubuntu9) ...

Setting up kword (1.5.0-0ubuntu9) ...

username@ubuntu:~$ sudo apt-get remove kword
Reading package lists... Done
Building dependency tree... Done
The following packages will be REMOVED:
kword
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0B of archives.
After unpacking 7000kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 111678 files and directories currently installed.)
Removing kword ...
username@ubuntu:~$

### 解决 `sudo apt-get install aptitude` 报错方案 当遇到 `sudo apt-get install aptitude` 命令报错的情况时,可以采取一系列措施来解决问题并成功安装 aptitude 工具。 #### 清理包缓存 有时旧的或损坏的包可能会引起问题。可以通过清理包缓存来尝试修复此问题: ```bash sudo apt-get clean sudo apt-get autoclean ``` #### 更新软件源列表 确保拥有最新的软件源列表有助于避免因过期镜像引起的错误: ```bash sudo apt-get update ``` 如果更新过程中也遇到了错误,则可能是网络连接不稳定或是所使用的APT源有问题。此时建议更换更稳定的国内镜像站[^1]。 #### 检查并修正破损依赖关系 对于已经存在的破损依赖项,可利用现有的 apt-get 功能来进行初步处理: ```bash sudo apt-get check sudo apt-get -f install ``` 上述命令能够帮助发现潜在的问题,并试图自动修复一些简单的依赖冲突。 #### 使用 aptitude 安装 aptitude (绕过 apt-get 的局限性) 由于提到 aptitude 能够更加智能地解决依赖问题,在某些情况下即使通过 apt-get 遇到困难也可以考虑直接下载 .deb 文件并通过 dpkg 手动安装 aptitude 或者借助其他方法获取 aptitude 并完成安装过程。不过最简单的方式还是先按照提示安装 aptitude 来替代 apt-get 进行操作: ```bash sudo apt-get install aptitude ``` 假如以上步骤仍然无法解决问题,可能是因为系统中有严重的依赖破坏或者其他深层次的原因。这时推荐使用 Live CD/USB 启动计算机进入救援模式进行进一步排查;或者备份数据后重新安装操作系统作为最后的选择。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值