網站搜尋

如何在 Linux 中找到套件版本


即使在圖形化套件管理器的幫助下套件管理變得更簡單,有些使用者仍然偏好使用命令列方式。在不同的 Linux 發行版中,有不同的命令可以查詢套件版本。今天,在本教學中,我們將會了解如何在一些流行的 Linux 發行版中查詢套件版本,例如 Alpine Linux、Arch Linux 及其衍生版本、Debian 及其衍生版本、RHEL 及其衍生版本。

在 Alpine Linux 中查找軟件包版本

要查看套件版本和其他詳細資料,請使用如下的 apk info 指令。

$ apk info vim

您將看到所給套件的小描述以及它所托管的網站。

範例輸出:

vim-8.2.2137-r0 description:
Improved vi-style text editor

vim-8.2.2137-r0 webpage:
https://www.vim.org/

vim-8.2.2137-r0 installed size:
18 MiB

gvim-8.2.2137-r0 description:
advanced text editor, with GUI

gvim-8.2.2137-r0 webpage:
https://www.vim.org/

gvim-8.2.2137-r0 installed size:
29 MiB

如您所見,已安裝的 Vim 版本是 8.2。

在基於 Arch 的系統中查找軟體包版本

要在 Arch Linux 及其衍生版本(如 EndeavourOS 和 Manjaro Linux)中查找已安裝套件(例如 VLC)的版本,請執行以下命令:

$ pacman -Q vlc

範例輸出:

vlc 2.2.4-3

如您在上述輸出中所見,已安裝的 VLC 套件版本為 2.2.4-3。

要顯示套件的詳細資訊,請執行:

$ pacman -Qi vlc

範例輸出:

Name : vlc
Version : 2.2.4-3
Description : A multi-platform MPEG, VCD/DVD, and DivX player
Architecture : x86_64
URL : http://www.videolan.org/vlc/
Licenses : LGPL2.1 GPL2
Groups : None
Provides : None
Depends On : a52dec libdvbpsi libxpm libdca libproxy sdl_image
 libdvdnav libtiger lua libmatroska zvbi taglib
 libmpcdec ffmpeg2.8 faad2 libupnp libshout libmad
 libmpeg2 xcb-util-keysyms libtar libxinerama
Optional Deps : avahi: for service discovery using bonjour protocol
 [installed]
 libnotify: for notification plugin [installed]
 gtk2: for notify plugin [installed]
 
 [...]

  lua-socket: for http interface
 qt4: for the GUI [installed]
Required By : None
Optional For : smtube
Conflicts With : vlc-plugin
Replaces : vlc-plugin
Installed Size : 53.28 MiB
Packager : Antonio Rojas <arojas@archlinux.org>
Build Date : Sun 24 Jul 2016 03:12:59 PM IST
Install Date : Fri 05 Aug 2016 11:22:54 AM IST
Install Reason : Explicitly installed
Install Script : No
Validated By : Signature

上述指令顯示完整的細節,如軟體包描述、版本、建置日期、安裝日期以及軟體包擁有者等。

相關閱讀:

  • Pacman 指令使用方式

在基於 DEB 的系統中查找軟件包版本

在 Debian、Ubuntu 及其衍生版本如 Linux Mint、Pop OS 和 Elementary OS 中,我們可以使用 dpkg 命令搭配 -l 選項來查找已安裝的套件,例如 Apache 網頁伺服器 的版本,如下所示:

$ dpkg -l apache2

或者,你可以使用 dpkg 搭配 grep 指令來獲取已安裝套件的版本,如下所示。

$ dpkg -s apache2 | grep -i version

範例輸出:

Version: 2.4.18-2ubuntu3.1

要顯示已安裝套件的詳細資訊,請執行:

$ dpkg -s apache2

範例輸出:

Package: apache2
Status: install ok installed
Priority: optional
Section: httpd
Installed-Size: 488
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 2.4.18-2ubuntu3.1
Replaces: apache2.2-bin, apache2.2-common
Provides: httpd, httpd-cgi
Depends: lsb-base, procps, perl, mime-support, apache2-bin (= 2.4.18-2ubuntu3.1), apache2-utils (>= 2.4), apache2-data (= 2.4.18-2ubuntu3.1)
Pre-Depends: dpkg (>= 1.17.14)
Recommends: ssl-cert
Suggests: www-browser, apache2-doc, apache2-suexec-pristine | apache2-suexec-custom, ufw
Conflicts: apache2.2-bin, apache2.2-common
Conffiles:
 /etc/apache2/apache2.conf da32fcc6a783acaebf0d74c17c726bf7
 /etc/default/apache-htcacheclean ae8721a0bc5b4e2ef7a5258b1e9db5c5

 [..]

 /etc/logrotate.d/apache2 7322a4f050c1e2454249695236a3472c
 /etc/ufw/applications.d/apache2-utils.ufw.profile f8d4fd920e598ceb4379613c6261f6af
Description: Apache HTTP Server
 The Apache HTTP Server Project's goal is to build a secure, efficient and
 extensible HTTP server as standards-compliant open source software. The
 result has long been the number one web server on the Internet.
 .
 Installing this package results in a full installation, including the
 configuration files, init scripts and support scripts.
Homepage: http://httpd.apache.org/
Original-Maintainer: Debian Apache Maintainers <debian-apache@lists.debian.org>

此外,我們可以使用 apt-show-versions 指令來查找套件版本:

$ apt-show-versions apache2

範例輸出:

apache2:amd64/xenial-security 2.4.18-2ubuntu3.1 uptodate
apache2:i386 not installed

如你在上述結果中所見,我已安裝了 64 位元版本的 apache2,其版本是 2.4.18。

如果未安裝 'apt-show-versions' 程式,您可以使用以下命令安裝它:

$ sudo apt install apt-show-versions

我們現在知道如何檢查已安裝套件的版本。那在線上儲存庫中的套件版本呢?有沒有辦法檢查官方儲存庫中可用套件的版本?這也是可能的。查看以下連結以了解方法。

  • 如何檢查 Ubuntu 軟體庫中套件的可用版本

即使這些套件尚未安裝在您的 Debian 系統中,您仍然可以查到它們的版本。更多細節請參考以下指南。

  • 如何在安裝前檢查 Linux 軟體包版本

在基於 RPM 的系統中查找軟件包版本

要在基於 RPM 的發行版(例如 Red Hat、CentOS、Fedora、AlmaLinux、Rocky Linux 和 openSUSE 等)中查找已安裝套件(例如 httpd)的版本,請執行:

$ rpm -qi httpd

範例輸出:

Name : httpd
Version : 2.4.6
Release : 40.el7.centos.4
Architecture: x86_64
Install Date: Thu 11 Aug 2016 08:08:45 PM IST
Group : System Environment/Daemons
Size : 9806117
License : ASL 2.0
Signature : RSA/SHA256, Mon 18 Jul 2016 09:35:16 PM IST, Key ID 24c6a8a7f4a80eb5
Source RPM : httpd-2.4.6-40.el7.centos.4.src.rpm
Build Date : Mon 18 Jul 2016 09:02:11 PM IST
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://httpd.apache.org/
Summary : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

上述命令會顯示已安裝套件的版本、建置日期、授權、描述等。如你在輸出中看到的,httpd 套件版本是 2.4.6。