在Ubuntu/Debian Linux系统上检查已经安装软件包的版本

如果要在Ubuntu/Debian Linux操作系统上检查已经安装软件包的版本(知道Ubuntu/Debian系统上可用的软件包版本),可使用apt、apt-cache、aptitude和apt-show-versions命令。

前言

在Linux中,所有应用程序均以程序包的形式分发,无非就是与程序包管理系统关联的文件。本文将向您展示一些命令,这些命令可用于检查Ubuntu/Debian Linux机器上的Package版本。

基于Debian的Linux系统附带两个主要的软件包管理器:

apt:从存储库管理软件包。

dpkg:管理下载到系统的软件包,通常为.deb格式。

aptitude的安装和使用方式与apt类似。

要在Ubuntu服务器/台式机上检查已安装软件包的版本,请使用下面介绍的其中一种方法即可。

在开始更新包APT索引之前,请执行以下操作:

sudo apt update

扩展参考:在Linux中安装和使用topgrade将已安装的软件包升级到最新版本

方法1:使用apt命令

apt命令具有一个选项列表,可用于检查在Ubuntu或Debian系统上安装的软件包的版本。

例如,要检查安装在Ubuntu/Debian服务器上的curl软件包的版本,请运行:

$ apt list curl

Listing... Done

curl/focal-updates,focal-security,now 7.68.0-1ubuntu2.2 amd64 [installed,automatic]

N: There is 1 additional version. Please use the '-a' switch to see it

要查看存储库中可用的软件包的所有版本,请使用-a选项:

$ apt list curl -a

Listing... Done

curl/focal-updates,focal-security 7.68.0-1ubuntu2.5 amd64 [upgradable from: 7.68.0-1ubuntu2.2]

curl/now 7.68.0-1ubuntu2.2 amd64 [installed,upgradable to: 7.68.0-1ubuntu2.5]

curl/focal 7.68.0-1ubuntu2 amd64

这包括存储库上可用于安装的所有其他软件包。

有关该软件包的更多详细信息,请使用apt show:

$ apt show curl

Package: curl

Version: 7.68.0-1ubuntu2.5

Priority: optional

Section: web

Origin: Ubuntu

Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>

Original-Maintainer: Alessandro Ghedini <ghedo@debian.org>

Bugs: https://bugs.launchpad.net/ubuntu/+filebug

Installed-Size: 411 kB

Depends: libc6 (>= 2.17), libcurl4 (= 7.68.0-1ubuntu2.5), zlib1g (>= 1:1.1.4)

Homepage: http://curl.haxx.se

Task: server, cloud-image, ubuntu-budgie-desktop

Download-Size: 161 kB

有关docker-ce软件包的所有版本的详细信息,请使用:

$ apt show curl -a

方法2:使用apt-cache

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

$ apt-cache policy curl

curl:

Installed: 7.68.0-1ubuntu2.2

Candidate: 7.68.0-1ubuntu2.5

Version table:

7.68.0-1ubuntu2.5 500

500 http://mirrors.digitalocean.com/ubuntu focal-updates/main amd64 Packages

500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages

*** 7.68.0-1ubuntu2.2 100

100 /var/lib/dpkg/status

7.68.0-1ubuntu2 500

500 http://mirrors.digitalocean.com/ubuntu focal/main amd64 Packages

第一行显示已安装的版本:

Installed: 7.68.0-1ubuntu2.2 --> Show installed version

如果未安装该软件包,则“已安装密钥”的值将不会显示为:

Installed: (none)

其他行提供有关存储库中其他可用软件包的信息。使用apt-cache madison将提供相同的输出:

$ apt-cache madison curl

curl | 7.68.0-1ubuntu2.5 | http://mirrors.digitalocean.com/ubuntu focal-updates/main amd64 Packages

curl | 7.68.0-1ubuntu2.5 | http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages

curl | 7.68.0-1ubuntu2 | http://mirrors.digitalocean.com/ubuntu focal/main amd64 Packages

方法3:使用aptitude

Ubuntu并没有提供aptitude,您可以使用以下方法进行安装:

sudo apt update

sudo apt install aptitude -y

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

$ aptitude versions curl

aptitude versions curl

p A 7.68.0-1ubuntu2     focal     500

i A 7.68.0-1ubuntu2.2     100

p A 7.68.0-1ubuntu2.5     focal-security,focal-updates     500

方法4:使用apt-show-versions

apt-show-versions命令用于列出可用的带有发行版的软件包版本。安装软件包:

sudo apt update

sudo apt install apt-show-versions -y

使用命令查询已安装的软件包版本:

$ apt-show-versions curl

curl:amd64/focal-security 7.68.0-1ubuntu2.2 upgradeable to 7.68.0-1ubuntu2.5

未安装在系统中的软件包的输出:

$ apt-show-versions mariadb-server

mariadb-server:all not installed

带有grep过滤器的dpkg命令可以显示已安装软件包的版本:

$ dpkg -s curl | grep Version

Version: 7.68.0-1ubuntu2.2

如上所示,Version后面就是已安装软件包的版本。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值