如何列出在Linux中具有可用更新的软件包

时间:2020-03-05 15:28:48  来源:igfitidea点击:

在本文中,将介绍如何列出可从Linux系统上的命令行安装的软件包更新数量。
我使用以下工具apt,apt-get,aptitude,yum,apt-check脚本和apticron列出更新。

使用apt命令(Ubuntu 14.04以上)

从ubuntu 14.04开始,我们有了一个名为“ apt”的新命令。
以下命令将列出我们可以更新的所有软件包,它们的当前版本以及新版本。

sudo apt list --upgradable
Listing... Done
gnupg/stable 1.4.18-7+deb8u2 amd64 [upgradable from: 1.4.18-7+deb8u1]
gpgv/stable 1.4.18-7+deb8u2 amd64 [upgradable from: 1.4.18-7+deb8u1]
libgcrypt20/stable 1.6.3-2+deb8u2 amd64 [upgradable from: 1.6.3-2+deb8u1]
libidn11/stable 1.29-1+deb8u2 amd64 [upgradable from: 1.29-1+deb8u1]
linux-image-3.16.0-4-amd64/stable 3.16.36-1+deb8u1 amd64 [upgradable from: 3.16.7-ckt25-2+deb8u3]

通常,此命令应在apt更新后运行。
如果有任何更新,它将显示可以更新多少个软件包,并提到可以显示哪些软件包可以升级的命令。

使用apt-get命令

我列出了apt-get命令的一些选项,以列出可用的软件包进行升级。

apt-get upgrade --dry-run
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  libsqlite0 pgdg-keyring
Use 'apt-get autoremove' to remove them.
The following packages have been kept back:
  linux-generic linux-headers-generic linux-image-generic
The following packages will be upgraded:
  apparmor apport apt apt-transport-https apt-utils base-files bash bind9-host
  libapt-inst1.5 libapt-pkg4.12 libbind9-90 libblkid1 libc-bin libc-dev-bin
  libc6 libc6-dev libcairo-gobject2 libcairo-script-interpreter2 libcairo2
  libcairo2-dev libcgmanager0 libcomerr2 libcurl3-gnutls libdbus-1-3
  libdbus-1-dev libdns100 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2
  ...
  python-software-properties python-urllib3 python3-apport python3-apt
  python3-distupgrade python3-problem-report rsyslog systemd-services tcpdump
  util-linux uuid-runtime wget wpasupplicant x11-common x11proto-core-dev
  xtrans-dev
161 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
Inst base-files [7.2ubuntu5.1] (7.2ubuntu5.2 Ubuntu:14.04/trusty-updates [amd64])
Conf base-files (7.2ubuntu5.2 Ubuntu:14.04/trusty-updates [amd64])
Inst bash [4.3-7ubuntu1.4] (4.3-7ubuntu1.5 Ubuntu:14.04/trusty-updates [amd64])
...

请注意,--dry-run允许我们查看将升级的文件/软件包的列表,但不会进行任何更改。

这是可用的模拟选项-只是打印,-s,--simulate,--dry-run,--recon,--no-act

几个例子

# apt-get -s dist-upgrade | grep "^[[:digit:]]\+ upgraded"
87 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
# apt-get -s dist-upgrade | grep -Po "^[[:digit:]]+ (?=upgraded)"
87
# apt-get dist-upgrade -s --quiet=2 | grep ^Inst | wc -l
87

使用aptitude命令

要从“ aptitude”命令获取信息,请使用以下命令获取准备升级的软件包列表。
某些版本的aptitude不需要在~U前后使用单引号。

aptitude search '~U'
...
i   scudcloud                                                                                                      - ScudCloud is a non official desktop client for Slack                                                                     
i   shim-signed                                                                                                    - Secure Boot chain-loading bootloader (Microsoft-signed binary)                                                           
i   smbclient                                                                                                      - command-line SMB/CIFS clients for Unix                                                                                   
i   strongswan                                                                                                     - IPsec VPN solution metapackage                                                                                           
i A strongswan-ike                                                                                                 - strongSwan Internet Key Exchange (v2) daemon                                                                             
i A strongswan-plugin-openssl                                                                                      - strongSwan plugin for OpenSSL                                                                                            
i A strongswan-starter                                                                                             - strongSwan daemon starter and configuration file parser                                                                  
i   sudo                                                                                                           - Provide limited super user privileges to specific users   
...

注意:它不会在线搜索,只会在系统中本地搜索。

如何使用apt-check脚本进行检查

使用此脚本,我能够在ubuntu 14.04上获得整洁的输出。

# /usr/lib/update-notifier/apt-check -p
bind9-host
python3-problem-report
liblwres90
linux-headers-generic
libdns100
libisccfg90
...

/usr/lib/update-notifier/apt-check-人类可读
可以更新33个软件包。

30个更新是安全更新。

使用yum和up2date命令

Yum是一个软件包管理器,可以在基于RPM的系统上安装,更新和删除软件包。
它会自动计算依赖关系,并弄清楚安装软件包应该发生的情况。
列出可用于已安装软件包的更新:

yum list updates
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.hyve.com
 * epel: mirrors.coreix.net
 * extras: centos.hyve.com
 * rpmforge: www.mirrorservice.org
 * updates: mirror.sov.uk.goscomb.net
kernel.x86_64                                                     2.6.32-504.3.3.el6  
...

下一个实用程序是up2date。
该实用程序从RHN(红帽网络)下载软件包并将其安装在系统上。
使用up2date来更新/安装软件包的优点是,它可以自动解决依赖性并下载我们可能需要的其他软件包。
它具有-l选项,向我们显示哪些软件包更新可用于下载和安装。

up2date -l

Apticron工具-通过电子邮件将更新列表发送给我们

如果我们需要机器在新软件包可用时自动提醒我们,则apticron可能只是我们要寻找的软件包。
Apticron是一个简单的shell脚本,每天从cron调用一次。
但是我们需要先安装它:

sudo apt-get install apticron

并配置:

vim /etc/apticron/apticron.conf
EMAIL="[email protected]"

现在,当有新的软件包可用时,apticron将每天发送一次电子邮件。
电子邮件示例如下所示:

apticron report [Mon, 10 May 2016 10:42:01 -0800]
========================================================================
apticron has detected that some packages need upgrading on:
[your machine name]
[ 1.2.3.4 ]
The following packages are currently pending an upgrade:
xfree86-common 4.3.0.dfsg.1-14sarge3
libice6 4.3.0.dfsg.1-14sarge3
libsm6 4.3.0.dfsg.1-14sarge3
xlibs-data 4.3.0.dfsg.1-14sarge3
libx11-6 4.3.0.dfsg.1-14sarge3
libxext6 4.3.0.dfsg.1-14sarge3
libxpm4 4.3.0.dfsg.1-14sarge3
========================================================================
Package Details:
Reading changelogs...
--- Changes for xfree86 (xfree86-common libice6 libsm6 xlibs-data libx11-6 libxext6 libxpm4) --
xfree86 (4.3.0.dfsg.1-14sarge3) stable-security; urgency=high
* Non-maintainer update by the Security Team:
Fixes several vulnerabilities reported by iDefense
(CVE-2006-6101, CVE-2006-6102, CVE-2006-6103)
-- Moritz Muehlenhoff Sun, 9 May 2016 13:31:35 +0000
========================================================================
You can perform the upgrade by issuing the command:
apt-get dist-upgrade
as root on faustus.example.com
It is recommended that you simulate the upgrade first to confirm that
the actions that would be taken are reasonable. The upgrade Jan be
simulated by issuing the command:
apt-get -s dist-upgrade
-- apticron

使计算机的软件保持最新是保护系统的最重要的一项任务。
Ubuntu可以提醒我们有待更新,也可以配置为自动应用更新。