ubuntuやdebianでファイル名からパッケージを探すapt-file が超便利

ubuntu やdebian で no such file or directory .. みたいなエラーを素早く解決します。

そもそもファイルがないって言ってるんだから、パッケージが足りてない可能性高いしので、ググりたくもない。

たとえば、こういうような例

[SOLVED] Missing predefs.h

/usr/include/features.h:323:26: 
fatal error: bits/predefs.h: No such file or directory

そんなときは apt-file コマンドで bits/predefs.h を含むパッケージを見つけてやればよいです。

apt-file はデフォではインストールされてないので、次のようにインストールします。。

% sudo apt-get update
% sudo apt-get install apt-file -y

apt-file がインストールされたら次のような文章が表示されます.

The system-wide cache is empty. You may want to run 'apt-file update'
as root to update the cache. You can also run 'apt-file update' as
normal user to use a cache in the user's home directory.

素直に apt-file update を実行してcache を更新します.

% sudo apt-file update

これで準備万端

上記の例だと

$ sudo apt-file search bits/predefs.h
libc6-dev: /usr/include/x86_64-linux-gnu/bits/predefs.h
libc6-dev-armel-cross: /usr/arm-linux-gnueabi/include/bits/predefs.h
libc6-dev-armhf-cross: /usr/arm-linux-gnueabihf/include/bits/predefs.h

libc6-dev か libc6-dev-armel-cross か ibc6-dev-armhf-cross をインストールすれば良いことがわかります。

redhat 系だと yum provides file名 で同等のことができます。