aptでインストールされたパッケージの一覧を表示させる方法

aptでインストールされたパッケージの一覧を表示させる方法です。

apt list --installed

Ubuntuでaptを使いインストールされたパッケージの一覧を表示させるには、下記のコマンドを実行します。

apt list --installed

実際に実行した結果です。

インストールされているパッケージ一覧がこのように一気に表示されます。

$ apt list --installed
Listing... Done
acpid/jammy,now 1:2.0.33-1ubuntu1 amd64 [installed]
adduser/jammy,now 3.118ubuntu5 all [installed,automatic]
alsa-topology-conf/jammy,now 1.2.5.1-2 all [installed,automatic]
alsa-ucm-conf/jammy-updates,now 1.2.6.3-1ubuntu1.8 all [installed,automatic]
amd64-microcode/jammy-updates,jammy-security,now 3.20191218.1ubuntu2.2 amd64 [installed,automatic]
apparmor/jammy-updates,now 3.0.4-2ubuntu2.2 amd64 [installed,automatic]

#####  以下省略  #####

結果を1画面分ずつ表示させたい

apt list --installedの実行結果を「|」(パイプ)でmoreやlessコマンドに渡してあげることで、実行結果を1画面分づつ表示させることができます。

スペースキーを押下すると、次の1画面分が表示されます。

$ apt list --installed | more

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Listing...
acpid/jammy,now 1:2.0.33-1ubuntu1 amd64 [installed]
adduser/jammy,now 3.118ubuntu5 all [installed,automatic]
alsa-topology-conf/jammy,now 1.2.5.1-2 all [installed,automatic]
alsa-ucm-conf/jammy-updates,now 1.2.6.3-1ubuntu1.8 all [installed,automatic]
amd64-microcode/jammy-updates,jammy-security,now 3.20191218.1ubuntu2.2 amd64 [installed,automatic]
apparmor/jammy-updates,now 3.0.4-2ubuntu2.2 amd64 [installed,automatic]
apport-symptoms/jammy,now 0.24 all [installed,automatic]
apport/jammy-updates,now 2.20.11-0ubuntu82.5 all [installed,automatic]
apt-transport-https/jammy-updates,now 2.4.10 all [installed]
apt-utils/jammy-updates,now 2.4.10 amd64 [installed,automatic]
apt/jammy-updates,now 2.4.10 amd64 [installed,automatic]
autoconf/jammy,now 2.71-2 all [installed]
automake/jammy,now 1:1.16.5-1.3 all [installed,automatic]
autotools-dev/jammy,now 20220109.1 all [installed,automatic]
base-files/jammy-updates,now 12ubuntu4.4 amd64 [installed]
base-passwd/jammy,now 3.5.52build1 amd64 [installed]
--More--

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.について

apt list の出力結果を「|」に渡すと、下記のメッセージが表示されますが問題はありません。

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

これは、「aptコマンドのCLIインターフェイスは安定していないので、スクリプト内で使用する場合は注意してください。」といった内容のメッセージになります。

ちなみに、aptのマニュアルには下記のように記述されています。

スクリプトの使い方およびほかの APT ツールとの違い
apt(8) コマンドラインはエンドユーザ向けツールとして設計されています。動作はバージョン間で変更される可能性があります。後方互換性を損なうことのないようには努めますが、変更がインタラクティブな使用に有益と思われる場合には、その保証はありません。

メッセージを表示させたくない場合

このメッセージは標準出力エラーで表示されるので、それを/dev/nullにリダイレクトしてしまう設定を行うことでメッセージを表示させないようにすることができます。。

$ apt list --installed 2>/dev/null | more
Listing...
acpid/jammy,now 1:2.0.33-1ubuntu1 amd64 [installed]
adduser/jammy,now 3.118ubuntu5 all [installed,automatic]
alsa-topology-conf/jammy,now 1.2.5.1-2 all [installed,automatic]
alsa-ucm-conf/jammy-updates,now 1.2.6.3-1ubuntu1.8 all [installed,automatic]
amd64-microcode/jammy-updates,jammy-security,now 3.20191218.1ubuntu2.2 amd64 [installed,automatic]

特定のパッケージを指定して表示

パッケージを指定して表示させることもできるので、インストールされているパッケージのバージョンを調べたりできます。

パッケージの後に「*」をつけてあげることで、関連するパッケージも合わせて表示できます。

apt list パッケージ* --installed

パッケージにopensshを指定して実行すると、バージョン1.8.9がインストールされていることが分かります。

$ apt list  openssh* --installed
Listing... Done
openssh-client/jammy-updates,now 1:8.9p1-3ubuntu0.4 amd64 [installed,automatic]
openssh-server/jammy-updates,now 1:8.9p1-3ubuntu0.4 amd64 [installed]
openssh-sftp-server/jammy-updates,now 1:8.9p1-3ubuntu0.4 amd64 [installed,automatic]

インストールされていないパッケージがある場合

aptで管理されているパッケージ一覧には存在しているが、インストールされていないパッケージがある場合はその旨のメッセージが表示されます。

Postfixに関するパッケージについて確認したところ、「N: There is 1 additional version. Please use the '-a' switch to see it」といったメッセージが表示されました。

このメッセージは、1つインストールされていないパッケージがあり、表示させるには「-a」オプションを使用してといった内容になります。

$ apt list  postfix* --installed
Listing... Done
postfix/jammy-updates,now 3.6.4-1ubuntu1.1 amd64 [installed]
N: There is 1 additional version. Please use the '-a' switch to see it

「-a」オプションを使用すると、インストールされていないパッケージも含めて表示されます。

「postfix/jammy 3.6.4-1ubuntu1 amd64」がインストールされていないパッケージなので[installed]の表記がありません。

$ apt list -a postfix* --installed
Listing... Done
postfix/jammy-updates,now 3.6.4-1ubuntu1.1 amd64 [installed]
postfix/jammy 3.6.4-1ubuntu1 amd64

grepで検索する方法もあります

apt list --installedコマンドの表示結果を「|」でgrepに渡してあげることで、表示させたいパッケージを検索することができます。

$ apt list --installed | grep openssh

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

openssh-client/jammy-updates,now 1:8.9p1-3ubuntu0.4 amd64 [installed,automatic]
openssh-server/jammy-updates,now 1:8.9p1-3ubuntu0.4 amd64 [installed]
openssh-sftp-server/jammy-updates,now 1:8.9p1-3ubuntu0.4 amd64 [installed,automatic]

パッケージ名だけを表示させたい

パッケージ名だけ表示させたい場合は、apt list --installedの実行結果を「|」でcutやawkコマンドに渡して処理することでパッケージ名だけを表示させることができます。

  • apt list --installed | cut -d'/' -f1
  • apt list --installed | awk -F "/" '{print $1}'

cutコマンドを使った例です。

-dで区切り文字を「/」と設定し、-f1で一番目を表示させるという内容になります。

$ apt list --installed | cut -d'/' -f1

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Listing...
acpid
adduser
alsa-topology-conf
alsa-ucm-conf
amd64-microcode
apparmor
#####   省略   #####

awkコマンドを使った例です。

-F "/" で区切り文字を「/」に設定して、1番目を表示させるという内容になります。

$ apt list --installed | awk -F "/" '{print $1}'

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Listing...
acpid
adduser
alsa-topology-conf
alsa-ucm-conf
amd64-microcode
apparmor
#####   省略   #####

コメント

タイトルとURLをコピーしました