文章目錄
  1. 1. 什么是apt-cache
    1. 1.1. pkgnames-查询安装包名
    2. 1.2. search-搜索软件包信息*
    3. 1.3. show-查询包的详细信息*
    4. 1.4. policy/madison-列出软件包的所有版本*
    5. 1.5. showpkg-查询依赖信息
    6. 1.6. stats-查询cache的统计信息
  2. 2. apt-get命令
    1. 2.1. 使用通配符安装
    2. 2.2. 安装软件包的特定版本
    3. 2.3. clean-清除缓存的包
    4. 2.4. changelog-更新日志*

  本方介绍如何在Debian/Ubuntu系统中快速地使用apt工具安装、卸载和查询软件包。

什么是apt-cache

  这个命对搜索软件包缓存非常有用,简单地说,它就是用来搜索和收集软件包信息,查找可安装包的。 下面介绍5个基本命令

pkgnames-查询安装包名

  如果要显示所有可安装包信息,可以用以下命令

1
$ sudo apt-cache pkgnames
1
2
3
4
5
6
7
8
9
10
11
account-plugin-yahoojp
ceph-fuse
dvd+rw-tools
e3
gnome-commander-data
grub-gfxpayload-lists
gweled
libannotation-indexer-java-doc
libboost-timer-dev
libdune-istl-dev
……

  如果是想列出所有以关键字开头的包,可以使用

1
$ sudo apt-cache pkgnames openssh
1
2
3
4
5
6
openssh-known-hosts
openssh-blacklist
openssh-server
openssh-sftp-server
openssh-client
openssh-blacklist-extra

search-搜索软件包信息*

  使用search命令可以方便地查询关键字匹配的软件包,并打印简介信息,例如如果想找vsftpd相关的包,你可以输入:

1
$ sudo apt-cache search vsftp

1
2
3
4
5
vsftpd - lightweight, efficient FTP server written for security
vsftpd-dbg - lightweight, efficient FTP server written for security (debug)
ccze - A robust, modular log coloriser
ftpd - File Transfer Protocol (FTP) server
yasat - simple stupid audit tool

show-查询包的详细信息*

  如果想查询包的版本、检验和、大小、安装大小和类别等信息,可以使用show子命令:

1
$ sudo apt-cache show rabbitmq-server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Package: rabbitmq-server
Priority: extra
Section: net
Installed-Size: 4935
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: PKG OpenStack <openstack-devel@lists.alioth.debian.org>
Architecture: all
Version: 3.4.3-2
Depends: adduser, erlang-nox (>= 1:13.b.3) | esl-erlang, logrotate, init-system-helpers (>= 1.18~)
Filename: pool/main/r/rabbitmq-server/rabbitmq-server_3.4.3-2_all.deb
Size: 4114518
MD5sum: fb7d7bd912fadcb935892fd5ae82f475
SHA1: 7d86db6d82b11ff2ba8101adf2898d3f496ef21b
SHA256: 54910af6bfdd9962df2e1c212d703f3f54c5f974b897ff66441c5f9bfd0c0fdc
Description-en: AMQP server written in Erlang
RabbitMQ is an implementation of AMQP, the emerging standard for high
performance enterprise messaging. The RabbitMQ server is a robust and
scalable implementation of an AMQP broker.
Description-md5: 78e91bfb996ee4ae5d16c93298f5f6e8
Homepage: http://www.rabbitmq.com/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 9m

policy/madison-列出软件包的所有版本*

policy

1
$ apt-cache policy wireshark
1
2
3
4
5
6
7
8
9
10
wireshark:
Installed: 1.12.1+g01b65bf-4+deb8u1build0.15.04.1
Candidate: 1.12.1+g01b65bf-4+deb8u1build0.15.04.1
Version table:
*** 1.12.1+g01b65bf-4+deb8u1build0.15.04.1 0
500 http://archive.ubuntu.com/ubuntu/ vivid-updates/universe amd64 Packages
500 http://archive.ubuntu.com/ubuntu/ vivid-security/universe amd64 Packages
100 /var/lib/dpkg/status
1.12.1+g01b65bf-4 0
500 http://archive.ubuntu.com/ubuntu/ vivid/universe amd64 Packages

madison

1
$ apt-cache madison wireshark
1
2
3
4
5
6
wireshark | 1.12.1+g01b65bf-4+deb8u1build0.15.04.1 | http://archive.ubuntu.com/ubuntu/ vivid-updates/universe amd64 Packages
wireshark | 1.12.1+g01b65bf-4+deb8u1build0.15.04.1 | http://archive.ubuntu.com/ubuntu/ vivid-security/universe amd64 Packages
wireshark | 1.12.1+g01b65bf-4 | http://archive.ubuntu.com/ubuntu/ vivid/universe amd64 Packages
wireshark | 1.12.1+g01b65bf-4 | http://archive.ubuntu.com/ubuntu/ vivid/universe Sources
wireshark | 1.12.1+g01b65bf-4+deb8u1build0.15.04.1 | http://archive.ubuntu.com/ubuntu/ vivid-updates/universe Sources
wireshark | 1.12.1+g01b65bf-4+deb8u1build0.15.04.1 | http://archive.ubuntu.com/ubuntu/ vivid-security/universe Sources

showpkg-查询依赖信息

  使用showpkg子命令可以查询依赖包信息,哪些尚未安装等:

1
$ sudo apt-cache showpkg iotop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Package: iotop
Versions:
0.6-1 (/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_vivid_universe_binary-amd64_Packages)
Description Language:
File: /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_vivid_universe_binary-amd64_Packages
MD5: c4f12688909987c39522befde2f1ee20
Description Language: en
File: /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_vivid_universe_i18n_Translation-en
MD5: c4f12688909987c39522befde2f1ee20


Reverse Depends:
iotop:i386,iotop
util-vserver,iotop
ubuntu-benchmark-tools,iotop
Dependencies:
0.6-1 - python (2 2.7.1-0ubuntu2) python (3 2.8) iotop:i386 (0 (null))
Provides:
0.6-1 -
Reverse Provides:

stats-查询cache的统计信息

  此命令会显示cache的总体统计信息:

1
$ sudo apt-cache stats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Total package names: 63279 (1,266 k)
Total package structures: 106443 (5,961 k)
Normal packages: 73921
Pure virtual packages: 1123
Single virtual packages: 9439
Mixed virtual packages: 1911
Missing: 20049
Total distinct versions: 77815 (5,603 k)
Total distinct descriptions: 97792 (2,347 k)
Total dependencies: 594886 (16.7 M)
Total ver/file relations: 81336 (1,952 k)
Total Desc/File relations: 97792 (2,347 k)
Total Provides mappings: 16719 (334 k)
Total globbed strings: 171 (2,179 )
Total dependency version space: 2,810 k
Total slack space: 37.1 k
Total space accounted for: 30.5 M

apt-get命令

  关于基本的install update就不介绍了,补充一些不一定每个人都知道的。

使用通配符安装

1
sudo apt-get install "*name*"

安装软件包的特定版本

  有时因为特殊原因需要安装较早版本的软件包,这时可以先使用apt-cache madison|policy name,来获取所有可安装版本,再使用以下命令安装特定版本:

1
sudo apt-get install vsftpd=2.3.5-3ubuntu1

clean-清除缓存的包

  硬盘空间告急时可以使用此命令释放一定空间

1
sudo apt-get clean

changelog-更新日志*

  此命令也可以用来查询历史版本信息,例如:

1
$ sudo apt-get changelog wireshark

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
wireshark (1.12.1+g01b65bf-4+deb8u1build0.15.04.1) vivid-security; urgency=medium

* fake sync from Debian

-- Steve Beattie <sbeattie@ubuntu.com> Wed, 03 Jun 2015 12:55:00 -0700

wireshark (1.12.1+g01b65bf-4+deb8u1) jessie-security; urgency=high

* security fixes from Wireshark 1.12.5:
- The LBMR dissector could go into an infinite loop (CVE-2015-3809)
- The WebSocket dissector could recurse excessively (CVE-2015-3810)
- The WCP dissector could crash while decompressing data (CVE-2015-3811)
- The X11 dissector could leak memory (CVE-2015-3812)
- The packet reassembly code could leak memory (CVE-2015-3813)
- The IEEE 802.11 dissector could go into an infinite loop (CVE-2015-3814)
- The Android Logcat file parser could crash. Discovered by Hanno Böck.
(CVE-2015-3815)


-- Balint Reczey <balint@balintreczey.hu> Mon, 25 May 2015 21:48:45 +0200

wireshark (1.12.1+g01b65bf-4) unstable; urgency=high

* security fixes from Wireshark 1.12.4 (Closes: #780372):
……
文章目錄
  1. 1. 什么是apt-cache
    1. 1.1. pkgnames-查询安装包名
    2. 1.2. search-搜索软件包信息*
    3. 1.3. show-查询包的详细信息*
    4. 1.4. policy/madison-列出软件包的所有版本*
    5. 1.5. showpkg-查询依赖信息
    6. 1.6. stats-查询cache的统计信息
  2. 2. apt-get命令
    1. 2.1. 使用通配符安装
    2. 2.2. 安装软件包的特定版本
    3. 2.3. clean-清除缓存的包
    4. 2.4. changelog-更新日志*