後進のためのメモシリーズ。自分がよく使うやつ。

debian パッケージのインストール

$ sudo apt-get install --no-install-recommends <パッケージ名>

デフォルトだと recommends しているだけの必須ではないパッケージも一緒に入って時間がかかるので --no-install-recommends をつけるのが常套手段

/etc も含めて完全に消す

$ sudo apt-get --purge remove <パッケージ名>

remove だけだと /etc などが残る


インストール候補の debian パッケージのバージョンとレポジトリを調べる

$ sudo apt-cache policy linux-image-extra-virtual
linux-image-extra-virtual:
  Installed: 3.13.0.112.120
  Candidate: 3.13.0.112.120
  Version table:
 *** 3.13.0.112.120 0
        500 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
        100 /var/lib/dpkg/status
     3.13.0.24.28 0
        500 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

debian パッケージがインストール済みかを調べる

dpkg -l (--list) パッケージ名、または dpkg -l | grep パッケージ名

$ dpkg -l linux-headers-$(uname -r)
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                             Version        Architecture  Description
+++-================================-==============-=============-==========================================================
ii  linux-headers-3.13.0-112-generic 3.13.0-112.159 amd64         Linux kernel headers for version 3.13.0 on 64 bit x86 SMP

変にカスると終了コードが 1 (エラー) ではなく 0 (正常) になることがあるので注意

$ dpkg -l linux-headers
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name          Version Architecture Description
+++-=============-=======-============-==============================
un  linux-headers <none>  <none>       (no description available)
$ echo $?
0
$ dpkg -l unknown
dpkg-query: no packages found matching unknown
$ echo $?
1

終了コードでインストール済みかチェックする場合は dpkg -p (--print-avail) のほうが確実

$ dpkg -p linux-headers-$(uname -r)
Package: linux-headers-3.13.0-112-generic
Priority: optional
Section: devel
Installed-Size: 13185
Maintainer: Ubuntu Kernel Team <kernel-team@lists.ubuntu.com>
Architecture: amd64
Source: linux
Version: 3.13.0-112.159
Provides: linux-headers, linux-headers-3.0
Depends: linux-headers-3.13.0-112, libc6 (>= 2.14)
Size: 694058
Description: Linux kernel headers for version 3.13.0 on 64 bit x86 SMP
 This package provides kernel header files for version 3.13.0 on
 64 bit x86 SMP.
 .
 This is for sites that want the latest kernel headers.  Please read
 /usr/share/doc/linux-headers-3.13.0-112/debian.README.gz for details.
 $ echo $?
 0
$ dpkg -p linux-headers
dpkg-query: package 'linux-headers' is not available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
$ echo $?
1

インストールした packge に含まれていたファイルを一覧する

dpkg -L (--list-files)

$ dpkg -L wget
/.
/etc
/etc/wgetrc
/usr
/usr/bin
/usr/bin/wget
/usr/share
/usr/share/info
/usr/share/info/wget.info.gz
/usr/share/doc
/usr/share/doc/wget
/usr/share/doc/wget/MAILING-LIST
/usr/share/doc/wget/NEWS.gz
/usr/share/doc/wget/AUTHORS
/usr/share/doc/wget/copyright
/usr/share/doc/wget/changelog.Debian.gz
/usr/share/doc/wget/README
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/wget.1.gz

指定のファイルがどのパッケージに含まれているか探す

インストール済みのパッケージから探すだけであれば dpkg -S (--search) を使える

$ dpkg -S libelf
libelf1:amd64: /usr/share/doc/libelf1
libelf1:amd64: /usr/lib/x86_64-linux-gnu/libelf.so.1
libelf1:amd64: /usr/lib/x86_64-linux-gnu/libelf-0.158.so
libelf1:amd64: /usr/share/doc/libelf1/changelog.Debian.gz
libelf1:amd64: /usr/share/doc/libelf1/copyright

libelf1 だ。

インストール済みでないパッケージから探す場合は、
https://www.debian.org/distrib/packages から検索するか、apt-file search を使う

$ sudo apt-get install apt-file
$ sudo apt-file update
$ apt-file search libelf
...
libelf-dev: /usr/include/libelf.h
libelf-dev: /usr/lib/x86_64-linux-gnu/libelf.a
libelf-dev: /usr/lib/x86_64-linux-gnu/libelf.so
libelf-dev: /usr/share/doc/libelf-dev/changelog.Debian.gz
libelf-dev: /usr/share/doc/libelf-dev/copyright
...

依存しているパッケージの表示

apt-cache depends

$ apt-cache depends vim
vim
  Depends: vim-common
  Depends: vim-runtime
  Depends: libacl1
  Depends: libc6
  Depends: libgpm2
  Depends: libpython2.7
  Depends: libselinux1
  Depends: libtinfo5
  Suggests: <ctags>
    exuberant-ctags
  Suggests: vim-doc
  Suggests: vim-scripts

再帰的に取得するには apt-rdepends を使う

パッケージソースを持ってくる

apt-get source

$ apt-get source ttyrec

debian ディレクトリ内にあてているパッチがおいてある