ubuntu 包管理工具 apt 使用与进阶

1. 引言

ubuntu 作为目前最受欢迎的 linux 发行版,加上 windows 10 推出的 WSL 对 ubuntu 的支持,让 ubuntu 更加流行。
而作为一个操作系统,最重要的是应用生态的构建,而 ubuntu 有今天的市场占用,与他的包管理机制 — apt 是密不可分的。
apt 工具是基于 ubuntu 底层的包管理命令 dpkg 构建的一套强大便捷的包管理工具,除了我们日常使用的下载、更新以外,还有着非常多、非常强大的功能,本文我们就来深入了解一下吧。

2. apt 相关命令

  • update — 更新包列表
  • upgrade — 升级系统中已安装的包版本
  • install — 安装软件包
  • remove — 卸载软件包
  • autoremove — 仅删除不需要再次下载的软件包
  • purge — 彻底删除软件包(包括配置文件)
  • source — 下载源代码
  • build-dep — 自动下载安装编译某个软件所需要的软件包
  • dist-upgrade — 升级整个发行版
  • dselect-upgrade — 安装dselect的选择进行升级
  • clean — 删除本地缓存的所有升级包
  • autoclean — 删除本地缓存中无用的软件包
  • check — 检查是否存在有问题的依赖关系

3. 命令参数

apt 命令参数

参数 备注
-d,—download-only 仅下载,不安装
-f,—fix-broken 修复依赖问题(用于install和remove子命令)
-m,—ignore-missing,—fix-missing 忽略缺失的软件包。遇到无法下载的软件包,自动忽略
—no-download 禁止下载软件包。与-m配合,可以使apt只使用已经下载的软件包
-q,—quiet 静默模式,输出的信息适合做日志
-s,—simulate,—just-print 模拟测试,不做出实际操作,不改变系统
-y,—yes,—assume-yes 在系统提问时,自动应答yes
-u,—show-upgraded 显示已升级的软件包
-V,—verbose-versions 显示已安装和已升级的软件包的完整版本号
-b,—compile,—build 在源码包下载完成后进行编译
—ignore-hold 忽略被保留的软件包
—no-upgrade 不要升级软件包
—force-yes 强制回答yes
—print-uris 仅答应软件包地址,不安装
—purge 彻底删除,包括配置文件
—reinstall 重新安装软件包

4. 进阶 — apt-cache

有时,我们想看看即将要安装的软件包版本以及其他信息,并不想立即安装,那么,apt-chache 就可以派上用场了。

4.1. 查看简介 — apt-cache search

通过 apt-cache search 命令,我们可以查看某个包或近似的包的基本描述。
例如执行:

$ apt-cache search mongodb-clients
mongodb-clients – object/document-oriented database (client apps)

而执行  apt-cache search mongo 则显示:

apt-cache search mongo
libreoffice-l10n-mn – office productivity suite — Mongolian language package
python-bson – Python implementation of BSON for MongoDB
python-bson-ext – C-coded extension to the python-bson package
python-gridfs – Python implementation of GridFS for MongoDB
python-pymongo – Python interface to the MongoDB document-oriented database
python-pymongo-doc – Python interface to the MongoDB document-oriented database (documentation)
python-pymongo-ext – C-coded extension to the python-pymongo package
python3-bson – Python3 implementation of BSON for MongoDB
python3-bson-ext – C-coded extension to the python3-bson package
python3-gridfs – Python3 implementation of GridFS for MongoDB
python3-pymongo – Python3 interface to the MongoDB document-oriented database
python3-pymongo-ext – C-coded extension to the python3-pymongo package
ttf-unifont – TrueType version of GNU Unifont
unifont – font with a glyph for each visible Unicode Plane 0 character
xfonts-unifont – PCF (bitmap) version of GNU Unifont
collectd-core – statistics collection and monitoring daemon (core system)
fonts-noto-unhinted – “No Tofu” font families with large Unicode coverage (unhinted)
golang-github-rs-xid-dev – globally unique id generator thought for the web
golang-gopkg-mgo.v2-dev – Go library for MongoDB
jmeter-mongodb – Load testing and performance measurement application (mongodb module)
kamailio-mongodb-modules – mongodb modules for the Kamailio SIP server
libbson-1.0-0 – Library to parse and generate BSON documents – runtime files
libbson-dev – Library to parse and generate BSON documents – dev files
libbson-doc – Library to parse and generate BSON documents – documentation
libbson-perl – BSON serialization and deserialization for Perl

当你不确定包的实际名称时,不妨用 apt-cache search 命令搜索一下。

4.2. 查看详细信息 — apt-cache show

除了看一句话的简介,很多时候,我们也希望知道软件包各方面的详细信息,此时就要使用 apt-cache show 命令了。

$ apt-cache show mongodb-clients
Package: mongodb-clients
Architecture: amd64
Version: 1:3.6.3-0ubuntu1.1
Priority: optional
Section: universe/database
Source: mongodb
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian MongoDB Maintainers <pkg-mongodb-maintainers@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 70218
Depends: libboost-filesystem1.65.1, libboost-iostreams1.65.1, libboost-program-options1.65.1, libboost-system1.65.1, libc6 (>= 2.15), libgcc1 (>= 1:3.4), libgoogle-perftools4, libpcrecpp0v5 (>= 7.7), libsnappy1v5, libssl1.1 (>= 1.1.0), libstdc++6 (>= 6), libstemmer0d (>= 0+svn527), libyaml-cpp0.5v5, zlib1g (>= 1:1.2.0)
Recommends: mongo-tools
Replaces: mongodb (<= 1:1.4.2-2)
Filename: pool/universe/m/mongodb/mongodb-clients_3.6.3-0ubuntu1.1_amd64.deb
Size: 20199136
MD5sum: 3afa3bba7295acf2802da34f028303d4
SHA1: 63a3a666c02a773cdd08b63d9c0edf4084e2d712
SHA256: c0b313b9a8c401e47daa4d150904e24b3207f2f69508c9048942dfd58e2ce910
Homepage: https://www.mongodb.org
Description-en: object/document-oriented database (client apps)
MongoDB is a high-performance, open source, schema-free
document-oriented data store that’s easy to deploy, manage
and use. It’s network accessible, written in C++ and offers
the following features:
.
 Collection oriented storage – easy storage of object-style data Full index support, including on inner objects
 Query profiling Replication and fail-over support
 Efficient storage of binary data including large objects (e.g. videos) Auto-sharding for cloud-level scalability
.
High performance, scalability, and reasonable depth of
functionality are the goals for the project.
.
This package contains the standard administrative shell (mongo) and other
utilities for administration or analysis of performance of the server.
Description-md5: 4a9a420d4a119483f9c8b9e74d827f5c

Package: mongodb-clients
Architecture: amd64
Version: 1:3.6.3-0ubuntu1
Priority: optional
Section: universe/database
Source: mongodb
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian MongoDB Maintainers <pkg-mongodb-maintainers@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 70214
Depends: libboost-filesystem1.65.1, libboost-iostreams1.65.1, libboost-program-options1.65.1, libboost-system1.65.1, libc6 (>= 2.15), libgcc1 (>= 1:3.4), libgoogle-perftools4, libpcrecpp0v5 (>= 7.7), libsnappy1v5, libssl1.1 (>= 1.1.0), libstdc++6 (>= 6), libstemmer0d (>= 0+svn527), libyaml-cpp0.5v5, zlib1g (>= 1:1.2.0)
Recommends: mongo-tools
Replaces: mongodb (<= 1:1.4.2-2)
Filename: pool/universe/m/mongodb/mongodb-clients_3.6.3-0ubuntu1_amd64.deb
Size: 20194524
MD5sum: cfc0edbc8959e3147f3c218a2d2055b2
SHA1: e593577e9048e2abb22dbce402545500ad8a7181
SHA256: ce5691c6eb5e47e259d8ee63d7d80ab993dda9b859c65b86ae5362cf9fa2e228
Homepage: https://www.mongodb.org
Description-en: object/document-oriented database (client apps)
MongoDB is a high-performance, open source, schema-free
document-oriented data store that’s easy to deploy, manage
and use. It’s network accessible, written in C++ and offers
the following features:
.
 Collection oriented storage – easy storage of object-style data Full index support, including on inner objects
 Query profiling Replication and fail-over support
 Efficient storage of binary data including large objects (e.g. videos) Auto-sharding for cloud-level scalability
.
High performance, scalability, and reasonable depth of
functionality are the goals for the project.
.
This package contains the standard administrative shell (mongo) and other
utilities for administration or analysis of performance of the server.
Description-md5: 4a9a420d4a119483f9c8b9e74d827f5c

5. apt 的相关文件和默认路径

apt 的相关文件和默认路径

路径 备注
/etc/apt/sources.list 设置软件包的获取来源
/etc/apt/apt.conf apt配置文件
/etc/apt/apt.conf.d/ apt的零碎配置文件
/etc/apt/preferences 版本参数
/var/cache/apt/archives/ 存放已经下载的软件包
/var/cache/apt/archives/partial 存放正在下载的软件包
/var/lib/apt/lists/ 存放已经下载的软件包详细信息
/var/lib/apt/lists/partial/ 存放正在下载的软件包详细信息

6. 微信公众号

欢迎关注微信公众号,以技术为主,涉及历史、人文等多领域的学习与感悟,每周三到七篇推文,只有全部原创,只有干货没有鸡汤。

阅读原文

ubuntu 包管理工具 apt 使用与进阶》来自互联网,仅为收藏学习,如侵权请联系删除。本文URL:http://www.bookhoes.com/361.html