LoginSignup
6
5

More than 5 years have passed since last update.

Debian apt系コマンドTips

Posted at

apt系コマンドのTips。インストールとか基本的な使い方は知ってる前提

スーパー牛さんパワー

$ apt moo
$ apt moo moo
$ apt moo moo moo
# 4つめ以降は上の3つがランダムで出現

インストール可能なバージョンが知りたい

apt list -aを使う

$ apt list -a weston
一覧表示... 完了
weston/testing,unstable 3.0.0-1 amd64 [1.12.0-3 からアップグレード可]
weston/now 1.12.0-3 amd64 [インストール済み、3.0.0-1 にアップグレード可]

globパターンが使用可能

$ apt list -a 'libwayland*'
一覧表示... 完了
libwayland-bin/testing,unstable,now 1.14.0-1 amd64 [インストール済み、自動]

libwayland-client0/testing,unstable,now 1.14.0-1 amd64 [インストール済み、自動]
libwayland-client0/不明 1.6.0-2 amd64

libwayland-cursor0/testing,unstable,now 1.14.0-1 amd64 [インストール済み、自動]
libwayland-cursor0/不明 1.6.0-2 amd64
# 以下省略

特定のバージョンをインストールしたい

$ apt list -a weston
一覧表示... 完了
weston/testing,unstable 3.0.0-1 amd64 [1.12.0-3 からアップグレード可]
weston/now 1.12.0-3 amd64 [インストール済み、3.0.0-1 にアップグレード可]

となっている場合

$ sudo apt install weston/testing

または

$ sudo apt install weston=3.0.0-1

としてバージョンの指定が可能

ファイルがどのパッケージに含まれているか調べる

apt-fileを使う

$ apt-file search weston.ini
weston: /usr/share/doc/weston/examples/weston.ini
weston: /usr/share/man/man5/weston.ini.5.gz

-xで正規表現も使える

$ apt-file search -x 'weston\.ini\.[0-9]'
weston: /usr/share/man/man5/weston.ini.5.gz

パッケージの被依存関係を表示

apt rdependsを使う

$ apt rdepends libwayland-client0
libwayland-client0
Reverse Depends:
  依存: libweston-3-0 (>= 1.11.91)
  依存: libegl1-mesa (>= 1.9.91)
  依存: libmutter0f (>= 1.5.90)
  依存: mpv (>= 1.9.91)
  依存: xwayland (>= 1.9.91)
  依存: gstreamer1.0-vaapi (>= 1.9.91)
# 以下省略

apt searchをパッケージ名のみにヒットさせる

apt searchはデフォルトでは説明文まで検索してしまう。
これを止めさせるには--names-onlyを付ければよい。

$ apt search --names-only compositor
# 以下省略

パッケージが持ってるファイルを知りたい

dpkg -Lを使用する

$ dpkg -L libdrm-dev
/.
/usr
/usr/include
/usr/include/libdrm
/usr/include/libdrm/amdgpu.h
/usr/include/libdrm/amdgpu_drm.h
/usr/include/libdrm/drm.h
# 以下省略

aptをスクリプトで使うのは良くない?!

aptの出力をパイプで繋いだりすると

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

と警告される

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5