这篇文章解释你如何快速学习从命令行使用apt-get和apt-cache安装、移除、升级和搜索软件包。这篇文章提供一些有用命令,它们将帮助你在基于Debian/Ubuntu的系统中处理包管理。

apt-get是什么?

apt-get工具是一个强大并且免费的包管理命令行程序,它用于与Ubuntu的APT库(高级包工具)一起使用来执行新软件包的安装,移除已有软件包,升级已有软件包甚至用于升级整个操作系统。

apt-cache是什么?

apt-cache命令行工具用于搜索apt软件包缓存。简单说,这个工具用于搜索软件包,收集包的信息并且也用于搜索什么可用包准备在基于Debian或Ubuntu系统上安装。

1、如何列出所有可用包?

要列出所有可用包,输入以下命令。

root@gyl-huawei:~# apt-cache pkgnames
libdatrie-doc
libfstrcmp0-dbg
librime-data-sampheng
task-estonian
python-pyao-dbg
fonts-georgewilliams
python3-doc8
...

2、如何查找包名和软件描述?

要在安装前查找包名及其描述,使用'search'标记。apt-cache和"search"一起使用将显示一个匹配包和短描述的列表。例如,查找包"vsftpd"的描述,则命令是:

root@gyl-huawei:~# apt-cache search vsftpd
ccze - robust, modular log coloriser
resource-agents - Cluster Resource Agents
vsftpd - lightweight, efficient FTP server written for security
vsftpd-dbg - lightweight, efficient FTP server written for security (debug)
yasat - simple stupid audit tool

要查找和列出所有以'vsftpd'开头的包,你可以使用以下命令。

root@gyl-huawei:~# apt-cache pkgnames vsftpd
vsftpd
vsftpd-dbg

3、如何检测包信息

例如,如果你想要检测包信息和其短描述(版本号,校验和,尺寸,安装尺寸,目录等)。按如下使用'show'子命令。

root@gyl-huawei:~# apt-cache show netcat
Package: netcat
Version: 1.10-41.1
Installed-Size: 16
Maintainer: Ruben Molina <rmolina@udea.edu.co>
Architecture: all
Depends: netcat-traditional (>= 1.10-39)
Description-en: TCP/IP swiss army knife -- transitional packageThis is a "dummy" package that depends on lenny's default version ofnetcat, to ease upgrades. It may be safely removed.
Description-md5: 1353f8c1d079348417c2180319bdde09
Tag: implemented-in::c, interface::commandline, network::client,protocol::ip, protocol::tcp, protocol::udp, role::program,scope::utility, use::downloading, use::transmission
Section: net
Priority: optional
Filename: pool/main/n/netcat/netcat_1.10-41.1_all.deb
Size: 9034
MD5sum: b2029ae3dbefc4154642127503d2e57f
SHA256: 26e2a9720cbd234ba3a2f769e59deb506e08356bfb08c71cd32b1f09c1e9cf42

4、如何检测特定包的依赖关系

使用'showpkg'子命令来检测特定软件包的依赖关系。那些依赖包是否安装了。例如,与包名一起使用'showpkg'命令。

root@gyl-huawei:~# apt-cache showpkg vsftpd
Package: vsftpd
Versions:
3.0.3-12 (/var/lib/apt/lists/repo.huaweicloud.com_debian_dists_buster_main_binary-amd64_Packages)Description Language:File: /var/lib/apt/lists/repo.huaweicloud.com_debian_dists_buster_main_binary-amd64_PackagesMD5: 81386f72ac91a5ea48f8db0b023f3f9bDescription Language: enFile: /var/lib/apt/lists/repo.huaweicloud.com_debian_dists_buster_main_i18n_Translation-enMD5: 81386f72ac91a5ea48f8db0b023f3f9bReverse Depends:vsftpd-dbg,vsftpd 3.0.3-12
Dependencies:
3.0.3-12 - debconf (18 0.5) debconf-2.0 (0 (null)) libc6 (2 2.28) libcap2 (2 1:2.10) libpam0g (2 0.99.7.1) libssl1.1 (2 1.1.0) libwrap0 (2 7.6-4~) adduser (0 (null)) libpam-modules (0 (null)) lsb-base (2 3.0-6) netbase (0 (null)) procps (0 (null)) ftp-server (0 (null)) logrotate (0 (null)) ssl-cert (0 (null)) ftp-server (0 (null))
Provides:
3.0.3-12 - ftp-server (= )
Reverse Provides:

5、如何检测缓存的统计数据

'stat'子命令将显示有关缓存的整体统计数据。例如,以下命令所有包名是在缓存中找到的包数。

root@gyl-huawei:~# apt-cache stats
Total package names: 84159 (1,683 k)
Total package structures: 84372 (3,712 k)Normal packages: 58736Pure virtual packages: 923Single virtual packages: 14226Mixed virtual packages: 623Missing: 9864
Total distinct versions: 63391 (5,071 k)
Total distinct descriptions: 123109 (2,955 k)
Total dependencies: 424554/106361 (10.2 M)
Total ver/file relations: 65154 (1,564 k)
Total Desc/File relations: 57573 (1,382 k)
Total Provides mappings: 19451 (467 k)
Total globbed strings: 182238 (4,074 k)
Total slack space: 21.9 k
Total space accounted for: 31.5 M
Total buckets in PkgHashTable: 50503Unused: 9524Used: 40979Utilization: 81.1417%Average entries: 2.05891Longest: 59Shortest: 1
Total buckets in GrpHashTable: 50503Unused: 9524Used: 40979Utilization: 81.1417%Average entries: 2.05371Longest: 9Shortest: 1

6、如何升级系统包

'update'命令用于与在/etc/apt/sources.list文件中指定的它们的源重新同步包索引文件。update命令从它们的位置获取这些包并且更新包到新的版本。

root@gyl-huawei:~# apt-get update
Get:1 http://repo.huaweicloud.com/debian buster InRelease [122 kB]
Get:2 http://repo.huaweicloud.com/debian buster-updates InRelease [56.6 kB]
...
Get:133 http://repo.huaweicloud.com/debian buster-proposed-updates/main amd64 Packages [99.9 kB]
Get:134 http://repo.huaweicloud.com/debian buster-proposed-updates/main Translation-en [66.1 kB]
Fetched 23.8 MB in 5s (4,410 kB/s)
Reading package lists... Done
N: Repository 'http://repo.huaweicloud.com/debian buster InRelease' changed its 'Version' value from '10.11' to '10.12'

7、如何升级软件包

'upgrade'命令用于升级在系统上所有当前安装的软件包。在任何情况下,不移除当前安装的包或者不获取和安装还未安装的包来满足升级依赖关系。

root@gyl-huawei:~# apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:base-files linux-image-amd64
The following packages will be upgraded:bind9-host chrony dirmngr distro-info-data dpkg dpkg-dev gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-clientgpg-wks-server gpgconf gpgsm gpgv grub-common grub-pc grub-pc-bin grub2-common gzip libbind9-161 libc-bin libc-dev-binlibc-l10n libc6 libc6-dev libdns-export1104 libdns1104 libdpkg-perl libexpat1 libexpat1-dev libfreetype6 libgnutls30libisc-export1100 libisc1100 libisccc161 libisccfg163 libldap-2.4-2 libldap-common liblwres161 liblzma5 libpcap0.8libsasl2-2 libsasl2-modules libsasl2-modules-db libssl1.1 libxml2 linux-libc-dev locales openssl rsyslog tzdata vimvim-common vim-runtime vim-tiny xxd xz-utils zlib1g
60 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
Need to get 50.0 MB of archives.
After this operation, 1,967 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...

如果你想要升级,不关注是否添加或移除软件包来满足依赖关系,使用'dist-upgrade'子命令。

root@gyl-huawei:~# apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:linux-image-4.19.0-21-amd64
The following packages have been kept back:base-files
The following packages will be upgraded:linux-image-amd64
1 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 48.5 MB of archives.
After this operation, 270 MB of additional disk space will be used.
Do you want to continue? [Y/n]
...

8、如何安装或升级特定软件包

'install'子命令用于安装或升级。

root@gyl-huawei:~# apt-get install netcat
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:netcat
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 9,034 B of archives.
After this operation, 16.4 kB of additional disk space will be used.
Get:1 http://repo.huaweicloud.com/debian buster/main amd64 netcat all 1.10-41.1 [9,034 B]
Fetched 9,034 B in 0s (69.6 kB/s)
Selecting previously unselected package netcat.
(Reading database ... 42001 files and directories currently installed.)
Preparing to unpack .../netcat_1.10-41.1_all.deb ...
Unpacking netcat (1.10-41.1) ...
Setting up netcat (1.10-41.1) ...

9、如何安装多个包

为了同时安装多个包,你可以在命令中添加多个包名称。例如,以下命令将安装包'nethogs'和'goaccess'。

root@gyl-huawei:~# apt-get install nethogs goaccess

10、如何使用通配符安装若干包

你可以用正则表达式用一个字符串添加若干包。例如,使用*通配符安装包含'*name*'字符串的若干包,名称将是'package-name'。

root@gyl-huawei:~# apt-get install '*name*'

11、如何安装没有升级的包

使用子'--no-upgrade'命令将阻止已经安装的包升级。

root@gyl-huawei:~# apt-get install packageName --no-upgrade

12、如何只升级特定包

'--only-upgrade'命令不安装新包,而它只升级已经安装的包并且禁用包的新安装。

root@gyl-huawei:~# apt-get install packageName --only-upgrade

13、如何安装特定包版本?

只想要安装包的特定版本,只要与包名一起使用'='并且跟上所要版本。

root@gyl-huawei:~# apt-get install vsftpd=3.0.3-12
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:vsftpd
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 0 B/153 kB of archives.
After this operation, 357 kB of additional disk space will be used.
Preconfiguring packages ...
Selecting previously unselected package vsftpd.
(Reading database ... 42050 files and directories currently installed.)
Preparing to unpack .../vsftpd_3.0.3-12_amd64.deb ...
Unpacking vsftpd (3.0.3-12) ...
Setting up vsftpd (3.0.3-12) ...
[vsftpd.conf:1] Line references path below legacy directory /var/run/, updating /var/run/vsftpd/empty → /run/vsftpd/empty; please update the tmpfiles.d/ drop-in file accordingly.
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for systemd (241-7~deb10u8) ...

14、如何移除包但不移除配置

要卸载软件包,而不移除它们的配置文件(为了之后再使用相同配置)。按以下使用'remove'。

root@gyl-huawei:~# apt-get remove vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:ssl-cert
Use 'apt autoremove' to remove it.
The following packages will be REMOVED:vsftpd
0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
After this operation, 357 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 42103 files and directories currently installed.)
Removing vsftpd (3.0.3-12) ...
Processing triggers for man-db (2.8.5-2) ...

15、如何完全移除包

要移除包括其配置文件的软件包,按如下使用'purge'子命令。

root@gyl-huawei:~# apt-get purge vsftpd

另外,你可以按如下组合两个命令一起。

root@gyl-huawei:~# apt-get remove --purge vsftpd

16、如何清理磁盘空间

'clean'命令用于通过从本地仓库清理获取的(下载的).deb文件(包)释放磁盘空间。

root@gyl-huawei:~# apt-get clean

17、如何只下载包的源代码

只下载特定包的源代码,与包名一起使用选项'--download-only source'。

root@gyl-huawei:~# apt-get --download-only source vsftpd
Reading package lists... Done
Need to get 234 kB of source archives.
Get:1 http://repo.huaweicloud.com/debian buster/main vsftpd 3.0.3-12 (dsc) [1,856 B]
Get:2 http://repo.huaweicloud.com/debian buster/main vsftpd 3.0.3-12 (tar) [197 kB]
Get:3 http://repo.huaweicloud.com/debian buster/main vsftpd 3.0.3-12 (diff) [35.2 kB]
Fetched 234 kB in 0s (541 kB/s)
Download complete and in download only mode

18、如何下载和解压一个包

要下载和解压一个包的源代码到一个特定目录,输入以下命令。

root@gyl-huawei:~# apt-get source vsftpd
Reading package lists... Done
Skipping already downloaded file 'vsftpd_3.0.3-12.dsc'
Skipping already downloaded file 'vsftpd_3.0.3.orig.tar.gz'
Skipping already downloaded file 'vsftpd_3.0.3-12.debian.tar.xz'
Need to get 0 B of source archives.
dpkg-source: info: extracting vsftpd in vsftpd-3.0.3
dpkg-source: info: unpacking vsftpd_3.0.3.orig.tar.gz
dpkg-source: info: unpacking vsftpd_3.0.3-12.debian.tar.xz
dpkg-source: info: using patch list from debian/patches/series
dpkg-source: info: applying 0020-manpage-hyphen.patch
...

19、如何下,解包和编译一个包

你也可以同时下载,解包和编译源代码,使用选项'--compile'。

 apt-get --compile source goaccess

20、如何下一个包,但不安装

使用'download'选项,你可以下载任何指定的包,而不安装它。例如,以下命令只下载'nethogs'包到当前工作目录。

root@gyl-huawei:~# apt-get download nethogs
Get:1 http://repo.huaweicloud.com/debian buster/main amd64 nethogs amd64 0.8.5-2+b1 [30.9 kB]
Fetched 30.9 kB in 0s (1,347 kB/s)
root@gyl-huawei:~# ls
nethogs_0.8.5-2+b1_amd64.deb

21、如何检测包的更改日志?

’changelog‘标记下载一个包的change-log并且显示被安装的包版本。

root@gyl-huawei:~# apt-get changelog vsftpd

22、如何检查损坏的依赖关系?

'check'命令是一个诊断工具。它用于更新包缓存并且检查损坏的依赖关系。

root@gyl-huawei:~# apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done

23、如何搜索和构建依赖关系?

'build-dep'命令在系统中搜索本地仓库并且为包安装构建依赖关系。如果在本地仓库中不存在包,它将返回一个错误代码。

root@gyl-huawei:~# apt-get build-dep netcat

24、如何自动清理Apt-Get缓存?

’autoclean‘命令删除来自/var/cache/apt/archives的所有.deb文件来释放显著的磁盘空间量。

root@gyl-huawei:~# apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done
root@gyl-huawei:~# apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done

25、如何自动移除安装的包?

'autoremove'子命令用于自动移除被安装来满足其它包依赖关系但现在不再需要的包。例如,以下命令将移除一个安装的包和其依赖关系。

root@gyl-huawei:~# apt-get autoremove vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:ssl-cert vsftpd
0 upgraded, 0 newly installed, 2 to remove and 2 not upgraded.
After this operation, 422 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 43307 files and directories currently installed.)
Removing ssl-cert (1.0.39) ...
Removing vsftpd (3.0.3-12) ...
Processing triggers for man-db (2.8.5-2) ...

26、检查一个包的所有依赖关系

这将帮助你显示有关你指定的一个特定包依赖关系的信息。

root@gyl-huawei:~# apt depends glances
glancesDepends: adduserDepends: lsb-base (>= 3.0-6)Depends: node-normalize.cssDepends: python3-pkg-resourcesDepends: python3-psutil (>= 2.0.0)Depends: <python3:any>python3Recommends: hddtempRecommends: lm-sensorsRecommends: python3-bottleRecommends: python3-dockerRecommends: python3-influxdbRecommends: python3-matplotlibRecommends: python3-netifacesRecommends: python3-pysnmp4Recommends: python3-pystacheSuggests: glances-doc

27、搜索一个包

search选项搜索指定包名并且显示所有匹配的包。

root@gyl-huawei:~# apt search apache2
Sorting... Done
Full Text Search... Done
apache2/oldstable-proposed-updates 2.4.38-3+deb10u8 amd64Apache HTTP Server
...

28、查看有关包的信息

这将帮助你显示有关包的信息,通过指定你想要显示有关信息的所有包运行这个命令。

root@gyl-huawei:~# apt show nmap
Package: nmap
Version: 7.70+dfsg1-6+deb10u2
Priority: optional
Section: net
Maintainer: Debian Security Tools <team+pkg-security@tracker.debian.org>
Installed-Size: 4,622 kB
Depends: nmap-common (= 7.70+dfsg1-6+deb10u2), libc6 (>= 2.15), libgcc1 (>= 1:3.0), liblinear3 (>= 2.01+dfsg), liblua5.3-0, libpcap0.8 (>= 0.9.8), libpcre3, libssh2-1 (>= 1.2.9), libssl1.1 (>= 1.1.0), libstdc++6 (>= 5.2), zlib1g (>= 1:1.1.4)
Suggests: ncat, ndiff, zenmap
Homepage: https://nmap.org/
Tag: admin::monitoring, implemented-in::c, interface::commandline,network::scanner, role::program, scope::utility, use::scanning
Download-Size: 1,894 kB
APT-Sources: http://repo.huaweicloud.com/debian buster/main amd64 Packages
Description: The Network MapperNmap is a utility for network exploration or security auditing. Itsupports ping scanning (determine which hosts are up), many portscanning techniques, version detection (determine service protocolsand application versions listening behind ports), and TCP/IPfingerprinting (remote host OS or device identification). Nmap alsooffers flexible target and port specification, decoy/stealth scanning,sunRPC scanning, and more. Most Unix and Windows platforms aresupported in both GUI and commandline modes. Several popular handhelddevices are also supported, including the Sharp Zaurus and the iPAQ.

用于包管理的基本命令APT-GET和APT-CACHE相关推荐

  1. ubuntu下使用apt安装mysql_Ubuntu下通过apt包管理安装mysql

    949 首页 > 资讯 > Ubuntu下通过apt包管理安装mysql Ubuntu下通过apt包管理安装mysql 消息来源:http://forum.ubuntu.org.cn/vi ...

  2. 5 个给 Linux 新手的最佳包管理器

    一个 Linux 新用户应该知道他或她的进步源自于对 Linux 发行版的使用,而 Linux 发行版有好几种,并以不同的方式管理软件包. 在 Linux 中,包管理器非常重要,知道如何使用多种包管理 ...

  3. Linux中RPM 和 YUM 包管理详解

    概述 在本教程中,学习如何使用 RPM 和 YUM 工具管理 Linux 系统上的包.学习: 使用 RPM 和 YUM 安装.重新安装.升级和删除包. 获取 RPM 包的信息,包括版本.状态.依赖项. ...

  4. linux发行版 以及 包管理方式

    linux发行版 以及 包管理方式 2010-07-26 14:24:41 分类:  linux 发行版 Debian --- Debian Project诞生于1993年8月13日,它的目标是提供一 ...

  5. Ubuntu系统利用snap包管理的使用

    Ubuntu系统利用snap包管理的使用 snap包管理工具的好处: 在apt软件管理工具中,在安装软件的同时会把所有的依赖包进行安装,如果出现这样的情况是没有办法解决的.如果在办公的过程中需要不同的 ...

  6. Linux RPM、YUM、APT包管理工具

    ⒈rpm包的管理 1)介绍 rpm是一种用于互联网下载包的打包及安装工具,它包含在某些Linux分发版中,它生成具有.RPM扩展名的文件,RPM是RedHat Package Manager(RedH ...

  7. Windows中使用包管理器(类似于apt/yum的) - Chocolatey

    Windows中使用包管理器 - Chocolatey简介 李俊才 的 CSDN 博客 邮箱 :291148484@163.com CSDN 主页:https://blog.csdn.net/qq_2 ...

  8. linux pkg文件,技术|Linux 包管理基础:apt、yum、dnf 和 pkg

    介绍 大多数现代的类 Unix 操作系统都提供了一种中心化的机制用来搜索和安装软件.软件通常都是存放在存储库中,并通过包的形式进行分发.处理包的工作被称为包管理.包提供了操作系统的基本组件,以及共享的 ...

  9. Linux 包管理基础:apt、yum、dnf 和 pkg

    介绍 大多数现代的类 Unix 操作系统都提供了一种中心化的机制用来搜索和安装软件.软件通常都是存放在存储库中,并通过包的形式进行分发.处理包的工作被称为包管理.包提供了操作系统的基本组件,以及共享的 ...

最新文章

  1. Go 学习笔记(32)— 类型系统(命名类型、未命名类型、底层类型、类型强制转换、类型别名和新声明类型)
  2. java调用asp.net webapi_通过HttpClient 调用ASP.NET Web API示例
  3. Java实现有向图的拓扑排序
  4. bzoj2226-[Spoj5971]LCMSum【欧拉函数,GCD】
  5. 建筑与计算机技术,建筑设计中常用的计算机技术与注意点
  6. (计算机组成原理)第五章中央处理器-第四节4:微程序控制单元设计
  7. 【和60】软件即服务的三重境界
  8. SMP、NUMA、MPP体系结构介绍
  9. c++ ftp服务端_重磅干货||五万字长文总结:C/C++ 知识(下篇)
  10. 【Ajax技术】JQuery的应用与高级调试技巧
  11. 电脑机房用成品——名词解释
  12. LINUX下载编译FriBidi
  13. 暴风影音2013校园招聘笔试题目——c语言D卷
  14. 手机语音通讯测试(Mobile Phone Communication Test)
  15. 锤子手机图片,音频,视频在哪个文件夹
  16. 第11课:词句分布式表达——词建模工具
  17. 中华名将索引 - 第一批:孙武
  18. 2020倒计时,大厂核心送给每一个脚踏实地努力着的Android程序员,逆风前行
  19. 利用Python创建Excel条形图
  20. 计算机不同进制数之间的转换,计算机进制数之间的转换002

热门文章

  1. CF97C Winning Strategy
  2. 导致程序员跳槽的原因
  3. lvgl移植到linux板子上
  4. 乱弹花絮——小小编辑送给乱弹精英和所有程序员的礼物
  5. 计算机网络英文论文,计算机网络应用英文论文翻译
  6. 蓝桥杯单片机第三届初赛程序设计——“自动售水机”设计任务书
  7. 【面经】宁波银行科技部测试岗一面面经
  8. 【JVM】本地方法栈与堆与方法区
  9. mac jemer 安装
  10. 计算机再带word打不开怎么办,小编教你电脑word打不开怎么办