如何在安装之前检查Linux包版本

时间:2020-03-21 11:44:10  来源:igfitidea点击:

大多数人都会知道如何在Linux中找到安装的包的版本。

但是,你会做什么来找到一个不安装的包版本?
没问题!本教程介绍如何检查Linux包版本,然后在Debian及其衍生物等ubuntu等中安装。
这个小小的小费可能有助于那些想知道他们在安装包之前的版本。

在安装之前检查Linux包版本

即使在基于Deb的系统中未安装,也有很多方法可以找到包装的版本。
其中我给了一些方法。

方法1 - 使用APT

简单运行的快速和肮脏的方式来检查包版本:

$apt show <package-name>

例子:

$apt show vim

示例输出:

Package: vim
Version: 2:8.0.1453-1ubuntu1.1
Priority: optional
Section: editors
Origin: Ubuntu
Maintainer: Ubuntu Developers <Hyman@theitroad>
Original-Maintainer: Debian Vim Maintainers <Hyman@theitroad>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 2,852 kB
Provides: editor
Depends: 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-scripts
Homepage: https://vim.sourceforge.io/
Task: cloud-image, server
Supported: 5y
Download-Size: 1,152 kB
APT-Sources: http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
Description: 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显示"命令显示,诸如包装的许多重要细节,

  • 软件包名字,
  • 版本,
  • 起源(从Vim来自其中),
  • 维护者,
  • 包装的主页,
  • 依赖性,
  • 下载大小,
  • 描述,
  • 很多。

因此,Ubuntu存储库中的Vim包的可用版本为8.0.1453.
这是我在Ubuntu系统上安装它的版本。

或者,如果我们喜欢短输出,请使用"APT策略"命令:

$apt policy vim
vim:
  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 vim
Listing... Done
vim/bionic-updates,bionic-security 2:8.0.1453-1ubuntu1.1 amd64
N: There is 1 additional version. Please use the '-a' switch to see it

APT是近期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... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  ctags vim-doc vim-scripts
The following NEW packages will be installed:
  vim
0 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包时会发生什么。

我们可以使用"升级"选项替换"安装"选项,以查看升级包时会发生什么。

$apt-get -s upgrade vim

方法3 - 使用Aptitude

Aptitude是NCURSES和CommandLine的前端,在Debian及其衍生物中的APT包管理器。

要查找具有Aptitude的包版本,只需运行:

$aptitude versions vim
p   2:8.0.1453-1ubuntu1                                                              bionic                                                        500 
p   2:8.0.1453-1ubuntu1.1                                                            bionic-security,bionic-updates                                500

我们还可以使用模拟选项(-s)来查看如果安装或者升级包会发生什么。

$aptitude -V -s install vim
The following NEW packages will be installed:
  vim [2:8.0.1453-1ubuntu1.1]  
0 packages upgraded, 1 newly installed, 0 to remove and 45 not upgraded.
Need to get 1,152 kB of archives. After unpacking 2,852 kB will be used.
Would download/install/remove packages.

其中-V标志用于显示包版本的详细信息。

同样,只需用"升级"选项替换"安装",以查看升级包时会发生什么。

$aptitude -V -s upgrade vim

使用aptitude命令找到未安装的包版本的另一种方法是:

$aptitude search vim -F "%c %p %d %V"

其中

  • -f用于指定应使用哪种格式来显示输出,
  • %c - 给定包的状态(安装或者未安装),
  • %p - 包的名称,
  • %d - 包的描述,
  • %v - 包的版本。

当我们不知道完整的包名称时,这是有帮助的。
此命令将列出包含给定字符串(i vim)的所有包。

以下是上述命令的示例输出:

[...]
p vim                                                           Vi IMproved - enhanced vi editor                                         2:8.0.1453-1ub
p vim-tlib                                                      Some vim utility functions                                               1.23-1        
p vim-ultisnips                                                 snippet solution for Vim                                                 3.1-3         
p vim-vimerl                                                    Erlang plugin for Vim                                                    1.4.1+git20120
p vim-vimerl-syntax                                             Erlang syntax for Vim                                                    1.4.1+git20120
p vim-vimoutliner                                               script for building an outline editor on top of Vim                      0.3.4+pristine
p vim-voom                                                      Vim two-pane outliner                                                    5.2-1         
p vim-youcompleteme                                             fast, as-you-type, fuzzy-search code completion engine for Vim           0+20151219+git

方法4 - 使用APT-Cache

APT-Cache命令用于在基于Debian的系统中查询APT缓存。
在APT的包缓存上执行许多操作是有用的。
一个精美的示例是,我们可以从某个存储库/PPA列出已安装的应用程序。

不仅仅安装了应用程序,我们也可以找到包装的版本,即使未安装它也是如此。
例如,以下命令将找到Vim软件包的版本:

$apt-cache policy vim

示例输出:

vim:
  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

我们可以在上面的输出中看到,未安装VIM。
如果我们想安装它,我们将获得8.0.1453版。
它还显示Vim包来自的存储库。

我们的一个读者曾在下面的"注释"部分中建议以下命令。

$apt-cache madison vim

示例输出:

vim | 2:8.0.1453-1ubuntu1.1 | http://it-mirrors.evowise.com/ubuntu bionic-updates/main amd64 Packages
vim | 2:8.0.1453-1ubuntu1.1 | http://it-mirrors.evowise.com/ubuntu bionic-security/main amd64 Packages
vim | 2:8.0.1453-1ubuntu1 | http://it-mirrors.evowise.com/ubuntu bionic/main amd64 Packages

方法5 - 使用APT-Show-insions

apt-show-versions命令用于列出Debian和基于Debian的系统中的已安装和可用包版本。
它还显示所有可升级包的列表。
如果我们有混合稳定/测试环境,它非常方便。
例如,如果我们启用了稳定和测试存储库,我们可以轻松查找从测试中的应用程序列表,也可以升级测试中的所有包。

默认情况下未安装APT-Show-explies。
我们需要使用命令安装它:

$sudo apt-get install apt-show-versions

安装后,运行以下命令以查找包版本,例如Vim:

$apt-show-versions -a vim
vim:amd64 2:8.0.1453-1ubuntu1   bionic          archive.ubuntu.com
vim:amd64 2:8.0.1453-1ubuntu1.1 bionic-security security.ubuntu.com
vim:amd64 2:8.0.1453-1ubuntu1.1 bionic-updates  archive.ubuntu.com
vim:amd64 not installed

其中-A交换机打印给定包的所有可用版本。

如果已安装给定包,则不需要使用-a选项。
在这种情况下,简单运行:

$apt-show-versions vim