如何在Ubuntu和Debian上检查已安装包的版本

时间:2020-02-23 14:32:39  来源:igfitidea点击:

我发现很多人问一个问题如何在我的Ubuntu系统上查看安装的包的版本?
,如何知道ubuntu/debian上可用的包版本?
本教程将显示很少可以有帮助的命令。
Ubuntu和Debian船用两个主要的包管理器:APT - 来自RepositoriesDPKG的软件包 - 管理下载到系统的软件包。
通常在.deb中可以安装

要检查Ubuntu Server /桌面上已安装包的版本,请使用以下任何方法:

方法1:使用APT命令

APT命令有一个选项列表,我们可以使用来检查Ubuntu或者Debian系统上安装的包的版本。
例如,要检查在我的Ubuntu 16.04服务器上安装的Docker-CE包的版本,我会运行:

$apt list docker-ce
Listing... Done
docker-ce/xenial,now 18.03.1~ce-0~ubuntu amd64 [installed]

要查看存储库上可用的包的所有版本,请传递-a选项。

$apt list docker-ce -a
Listing... Done
docker-ce/xenial,now 18.03.1~ce-0~ubuntu amd64 [installed]
docker-ce/xenial 18.03.0~ce-0~ubuntu amd64
docker-ce/xenial 17.12.1~ce-0~ubuntu amd64
docker-ce/xenial 17.12.0~ce-0~ubuntu amd64
docker-ce/xenial 17.09.1~ce-0~ubuntu amd64
docker-ce/xenial 17.09.0~ce-0~ubuntu amd64
docker-ce/xenial 17.06.2~ce-0~ubuntu amd64
docker-ce/xenial 17.06.1~ce-0~ubuntu amd64
docker-ce/xenial 17.06.0~ce-0~ubuntu amd64
docker-ce/xenial 17.03.2~ce-0~ubuntu-xenial amd64
docker-ce/xenial 17.03.1~ce-0~ubuntu-xenial amd64
docker-ce/xenial 17.03.0~ce-0~ubuntu-xenial amd64

列表是当前已安装的包,所有其他人都可以在存储库上使用以进行安装。

有关包的更多详细信息,请使用APT Show。

$apt show docker-ce
Package: docker-ce
Version: 18.03.1~ce-0~ubuntu
Priority: optional
Section: admin
Maintainer: Docker 
Installed-Size: 181 MB
Depends: iptables, init-system-helpers (>= 1.18~), lsb-base (>= 4.1+Debian11ubuntu7), libc6 (>= 2.17), libdevmapper1.02.1 (>= 2:1.02.97), libltdl7 (>= 2.4.6), libseccomp2 (>= 2.3.0), libsystemd0
Recommends: aufs-tools, ca-certificates, cgroupfs-mount | cgroup-lite, git, pigz, xz-utils, apparmor
Conflicts: docker (<< 1.5~), docker-ee, docker-engine, docker-engine-cs, docker.io, lxc-docker, lxc-docker-virtual-package
Replaces: docker-engine
Homepage: https://dockerproject.org
Download-Size: 34.0 MB
APT-Manual-Installed: yes
APT-Sources: https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
Description: Docker: the open-source application container engine
 Docker is an open source project to build, ship and run any application as a
 lightweight container
 .
 Docker containers are both hardware-agnostic and platform-agnostic. This means
 they can run anywhere, from your laptop to the largest EC2 compute instance and
 everything in between - and they don’t require you to use a particular
 language, framework or packaging system. That makes them great building blocks
 for deploying and scaling web apps, databases, and backend services without
 depending on a particular stack or provider.

有关Docker-CE包的所有版本的详细信息,请使用:

$apt show docker-ce -a

方法2:使用apt-cache

APT-Cache是用于查询APT缓存的Debian命令行工具。
它提供了从包元数据搜索和生成有趣的输出的操作。
要使用APT-Cache搜索包版本,运行:

$apt-cache policy docker-ce
docker-ce:
  Installed: 18.03.1~ce-0~ubuntu
  Candidate: 18.03.1~ce-0~ubuntu
  Version table:
 *** 18.03.1~ce-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
        100 /var/lib/dpkg/status
     18.03.0~ce-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.12.1~ce-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.12.0~ce-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.09.1~ce-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.09.0~ce-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.06.2~ce-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.06.1~ce-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.06.0~ce-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.03.2~ce-0~ubuntu-xenial 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.03.1~ce-0~ubuntu-xenial 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.03.0~ce-0~ubuntu-xenial 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

第一行显示已安装版本:

Installed: 18.03.1~ce-0~ubuntu --> Show installed version

另一线提供有关存储库上可用的其他包的信息。
使用APT-Cache Madison将提供相同的输出。

$apt-cache madison docker-ce
 docker-ce | 18.03.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 18.03.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.12.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.12.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.09.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.09.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.06.2~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.06.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.06.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.03.2~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

方法3:使用aptitude

Ubuntu发行版中不包含aptitude,我们可以使用:

$sudo apt-get install aptitude

要检查可用运行的软件包版本:

$aptitude versions docker-ce
p   17.03.0~ce-0~ubuntu-xenial                      xenial                      500 
p   17.03.1~ce-0~ubuntu-xenial                      xenial                      500 
p   17.03.2~ce-0~ubuntu-xenial                      xenial                      500 
p   17.06.0~ce-0~ubuntu                             xenial                      500 
p   17.06.1~ce-0~ubuntu                             xenial                      500 
p   17.06.2~ce-0~ubuntu                             xenial                      500 
p   17.09.0~ce-0~ubuntu                             xenial                      500 
p   17.09.1~ce-0~ubuntu                             xenial                      500 
p   17.12.0~ce-0~ubuntu                             xenial                      500 
p   17.12.1~ce-0~ubuntu                             xenial                      500 
p   18.03.0~ce-0~ubuntu                             xenial                      500 
i   18.03.1~ce-0~ubuntu                             xenial                      500