使用 Aptitude 进行 Linux 包管理


Aptitude 基于 Ncurses 构建 APT 前端和 Debian 包管理器,它是一个基于文本的工具,运行于终端或命令行界面 (CLI)。本文介绍了“使用 Aptitude 进行 Linux 包管理”。

什么是 APT?

apt 是一个命令行包管理器,提供用于搜索、管理以及查询包信息的命令。它提供与专用 APT 工具(如 apt-get 和 apt-cache)相同的功能,但默认情况下启用了更适合交互使用的选项。

要获取有关 APT 的更多信息,请使用以下命令:

$ apt

示例输出应如下所示:

apt 1.2.15 (amd64)
Usage: apt [options] command
apt is a commandline package manager and provides commands for
searching and managing as well as querying information about packages.
It provides the same functionality as the specialized APT tools,
like apt-get and apt-cache, but enables options which are more suitable for
interactive use by default.
Most used commands:
   list - list packages based on package names
   search - search in package descriptions
   show - show package details
   install - install packages
   remove - remove packages
   autoremove - Remove automatically all unused packages
   update - update list of available packages
   upgrade - upgrade the system by installing/upgrading packages
   full-upgrade - upgrade the system by removing/installing/upgrading packages
   edit-sources - edit the source information file
See apt(8) for more information about the available commands.
Configuration options and syntax is detailed in apt.conf(5).
Information about how to configure sources can be found in sources.list(5).
Package and version choices can be expressed via apt_preferences(5).
Security details are available in apt-secure(8).
This APT has Super Cow Powers.

包列表

要根据包名称获取包列表,请使用以下命令:

$ apt list

示例输出应如下所示:

revolution-r/xenial,xenial 3.0.0-1ubuntu1 all
revu-tools/xenial,xenial,trusty,trusty 0.6.1.5 all
rex/xenial,xenial 1.3.3-1 all
rexical/xenial,xenial 1.0.5-2build1 all
rexima/xenial 1.4-7build1 amd64
rfc5766-turn-server/trusty 3.2.3.1-1 amd64
rfcdiff/xenial,xenial 1.42-1 all
rfdump/xenial 1.6-4 amd64
rfkill/xenial,now 0.5-1ubuntu3 amd64 [installed,automatic]
rgbpaint/xenial,trusty 0.8.7-5 amd64
rgxg/xenial,trusty 0.1-1 amd64
rhash/xenial 1.3.3-1 amd64
rhc/xenial,xenial 1.38.4-2 all
rheolef/xenial 6.6-1build2 amd64
rheolef-doc/xenial,xenial 6.6-1build2 all
rhino/xenial,xenial 1.7R4-3 all
rhino-doc/xenial,xenial 1.7R4-3 all
rhinote/xenial,xenial,trusty,trusty 0.7.4-2 all
rhn-client-tools/xenial 1.8.26-4 amd64
rhnsd/xenial 5.0.4-3 amd64
..................................................................

安装包

要使用 APT 安装包,请使用以下命令:

$ sudo apt install firefox

上述命令安装 firefox。示例输出应如下所示:

Reading package lists... Done
Building dependency tree
Reading state information... Done
firefox is already the newest version (50.1.0+build2-0ubuntu0.16.04.1).
firefox set to manually installed.
The following packages were automatically installed and are no longer required:
   libterm-readkey-perl linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic
   linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic
   linux-signed-image-4.4.0-31-generic
Use 'sudo apt autoremove' to remove them.
..................................................................

删除包

要使用 APT 删除包,请使用以下命令:

$ sudo apt remove firefox

上述命令将从 Linux 中删除 firefox 包。示例输出应如下所示:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libterm-readkey-perl linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic
linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic
linux-signed-image-4.4.0-31-generic
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
firefox
0 upgraded, 0 newly installed, 1 to remove and 26 not upgraded.
After this operation, 114 MB disk space will be freed.

删除未使用的包

要自动删除所有未使用的包,请使用以下命令:

$ sudo apt autoremove

示例输出应如下所示:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
libterm-readkey-perl linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic
linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic
linux-signed-image-4.4.0-31-generic
0 upgraded, 0 newly installed, 6 to remove and 26 not upgraded.
After this operation, 295 MB disk space will be freed.
..............................................................................

更新包

要更新包,请使用以下命令:

$ sudo apt update

升级包

要通过安装/升级包来升级系统,请使用以下命令:

$ sudo apt upgrade

阅读本文后,您将能够理解“使用 Aptitude 进行 Linux 包管理”,我们将陆续推出更多基于 Linux 的技巧和提示。敬请关注!

更新于:2020年1月17日

279 次浏览

启动您的 职业生涯

通过完成课程获得认证

开始学习
广告