この記事では、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]
通常、このコマンドはaptupdateの後に実行する必要があります。 更新がある場合は、更新できるパッケージの数が表示され、アップグレードできるパッケージを表示するコマンドが表示されます。
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を使用すると、アップグレードされるファイル/パッケージのリストを表示できますが、変更は行われません。
使用可能なシミュレーションオプションは次のとおりです–just-print、-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スクリプトを使用してチェックする方法
このスクリプトを使用して、ubuntu14.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 –human-読み取り可能
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(Red Hat Network)からパッケージをダウンロードし、システムにインストールします。 up2dateを使用してパッケージを更新/インストールする利点は、依存関係を自動的に解決し、必要な追加パッケージをダウンロードすることです。 ダウンロードしてインストールできるパッケージアップデートを表示する-lオプションがあります。
up2date -l
Apticronツール-アップデートリストをメールで送信
新しいパッケージが利用可能になったときに自動的にアラートを出すようにマシンが必要な場合は、apticronが探しているパッケージにすぎない可能性があります。 Apticronは、cronから1日1回呼び出される単純なシェルスクリプトです。 ただし、最初にインストールする必要があります。
sudo apt-get install apticron
および構成:
vim /etc/apticron/apticron.conf
EMAIL="[email protected]"
これで、apticronは、新しいパッケージが利用可能になると、1日に1回メールを送信します。 メールのサンプルは次のようになります。
apticron report [Mon, 10 Jul 2017 10:42:01 -0800] ======================================================================== apticron has detected that some packages need upgrading on: [ 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 Jul 2017 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 may be simulated by issuing the command: apt-get -s dist-upgrade -- apticron
コンピュータのソフトウェアを最新の状態に保つことは、システムを保護するための唯一の最も重要なタスクです。 Ubuntuは保留中の更新について警告することができ、更新を自動的に適用するように構成することもできます。 更新によりサーバー上のサービスが再起動する可能性があるため、これがすべての環境に適しているとは限らないことに注意してください。