如何在安装之前检查 Linux 软件包的版本?


如何在安装之前检查 Linux 软件包的版本?

文章插图
【如何在安装之前检查 Linux 软件包的版本?】 
本文将介绍在 Debian 及其衍生品(如 Ubuntu)中,如何在软件包安装之前检查它的版本 。对于那些想在安装之前知道软件包版本的人来说,这个小技巧可能会有所帮助 。
-- Sk(作者)
大多数人都知道如何在 linux 中 查找已安装软件包的版本,但是,你会如何查找那些还没有安装的软件包的版本呢?很简单!本文将介绍在 Debian 及其衍生品(如 Ubuntu)中,如何在软件包安装之前检查它的版本 。对于那些想在安装之前知道软件包版本的人来说,这个小技巧可能会有所帮助 。
在安装之前检查 Linux 软件包版本在基于 DEB 的系统中,即使软件包还没有安装,也有很多方法可以查看他的版本 。接下来,我将一一介绍 。
方法 1 – 使用 Apt检查软件包的版本的懒人方法:
$ apt show <package-name>示例:
$ apt show vim示例输出:
Package: vimVersion: 2:8.0.1453-1ubuntu1.1Priority: optionalSection: editorsOrigin: UbuntuMaintainer: Ubuntu Developers <[email protected]>Original-Maintainer: Debian Vim Maintainers <[email protected]>Bugs: https://bugs.launchpad.net/ubuntu/+filebugInstalled-Size: 2,852 kBProvides: editorDepends: vim-common (= 2:8.0.1453-1ubuntu1.1), vim-runtime (= 2:8.0.1453-1ubuntu1.1), libacl1 (>= 2.2.51-8), libc6 (>= 2.15), libgpm2 (>= 1.20.7), libPython3.6 (>= 3.6.5), libselinux1 (>= 1.32), libtinfo5 (>= 6)Suggests: ctags, vim-doc, vim-scriptsHomepage: https://vim.sourceforge.io/Task: cloud-image, serverSupported: 5yDownload-Size: 1,152 kBAPT-Sources: http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 PackagesDescription: Vi IMproved - enhanced vi editor Vim is an almost compatible version of the UNIX editor Vi. . Many new features have been added: multi level undo, syntax highlighting, command line history, on-line help, filename completion, block operations, folding, Unicode support, etc. . This package contains a version of vim compiled with a rather standard set of features. This package does not provide a GUI version of Vim. See the other vim-* packages if you need more (or less).N: There is 1 additional record. Please use the '-a' switch to see it正如你在上面的输出中看到的,apt show 命令显示了软件包许多重要的细节,例如:
  1. 包名称,
  2. 版本,
  3. 来源(vim 来自哪里),
  4. 维护者,
  5. 包的主页,
  6. 依赖,
  7. 下载大小,
  8. 简介,
  9. 其他 。
因此,Ubuntu 仓库中可用的 Vim 版本是 8.0.1453 。如果我把它安装到我的 Ubuntu 系统上,就会得到这个版本 。
或者,如果你不想看那么多的内容,那么可以使用 apt policy 这个命令:
$ apt policy vimvim: Installed: (none) Candidate: 2:8.0.1453-1ubuntu1.1 Version table: 2:8.0.1453-1ubuntu1.1 500 500 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages 500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages 2:8.0.1453-1ubuntu1 500 500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages甚至更短:
$ apt list vimListing... Donevim/bionic-updates,bionic-security 2:8.0.1453-1ubuntu1.1 amd64N: There is 1 additional version. Please use the '-a' switch to see itapt 是 Ubuntu 最新版本的默认包管理器 。因此,这个命令足以找到一个软件包的详细信息,给定的软件包是否安装并不重要 。这个命令将简单地列出给定包的版本以及其他详细信息 。
方法 2 – 使用 Apt-get要查看软件包的版本而不安装它,我们可以使用 apt-get 命令和 -s 选项 。
$ apt-get -s install vim示例输出:
NOTE: This is only a simulation! apt-get needs root privileges for real execution. Keep also in mind that locking is deactivated, so don't depend on the relevance to the real current situation!Reading package lists... DoneBuilding dependency treeReading state information... DoneSuggested packages: ctags vim-doc vim-scriptsThe following NEW packages will be installed: vim0 upgraded, 1 newly installed, 0 to remove and 45 not upgraded.Inst vim (2:8.0.1453-1ubuntu1.1 Ubuntu:18.04/bionic-updates, Ubuntu:18.04/bionic-security [amd64])Conf vim (2:8.0.1453-1ubuntu1.1 Ubuntu:18.04/bionic-updates, Ubuntu:18.04/bionic-security [amd64])这里,-s 选项代表 模拟 。正如你在输出中看到的,它不执行任何操作 。相反,它只是模拟执行,好让你知道在安装 Vim 时会发生什么 。
你可以将 install 选项替换为 upgrade,以查看升级包时会发生什么 。
$ apt-get -s upgrade vim方法 3 – 使用 Aptitude在 Debian 及其衍生品中,aptitude 是一个基于 ncurses(LCTT 译注:ncurses 是终端基于文本的字符处理的库)和命令行的前端 APT 包管理器 。


推荐阅读