apt-file: search for files in packages, installed or not

January 24th, 2007 edited by lucas

Entry submitted by Paul Sundvall. DPOTD needs your help, please contribute !

Have you ever tried to compile some tar-ball and had to download missing dependencies? In that case, you probably needed to find out which packages were needed to fix those dependencies. Sometimes there is a README which states what you need, but that might not be that helpful sometimes.

One way of finding out which package needs to be installed is to use the debian package search page.

Another way is to use apt-file instead. It works as a local search engine, based on the apt sources you have in /etc/apt/sources.list.

To use apt-file, build the search database by issuing apt-file update as root. Then, as an ordinary user, search for a file with apt-file search file and you get the package names which contain the file you look for. Install them with apt-get, and your missing dependencies are gone with the wind!

apt-file is located in package apt-file in both Debian and Ubuntu.

after install, build the search database with apt-file update.


I tried to compile a simple pam example, which gave the following output:

pauls@voltaire:~/code/eget/all/pam$ make
gcc  pamexample.c  -o pamexample -lpam -lpam_misc
pamexample.c:12:31: error: security/pam_appl.h: Filen eller katalogen
finns inte
pamexample.c:13:31: error: security/pam_misc.h: Filen eller katalogen
finns inte

Seems like I need the (for me) unknown file pam_appl.h. Time to use apt-file!

pauls@voltaire:~/code/eget/all/pam$ apt-file search pam_appl.h
libpam-doc: usr/share/doc/libpam-doc/html/pam_appl.html
libpam0g-dev: usr/include/security/pam_appl.h
lsb-build-base2: usr/include/lsb2/security/pam_appl.h
lsb-build-base3: usr/include/lsb3/security/pam_appl.h

It seems like I should install libpam0g-dev

pauls@voltaire:~/code/eget/all/pam$ su -
voltaire:~# apt-get install libpam0g-dev
Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 118kB of archives.
After unpacking 365kB of additional disk space will be used.
Get: 1 unstable/main libpam0g-dev 0.79-4 [118kB]
Fetched 118kB in 2s (47.9kB/s)
Selecting previously deselected package libpam0g-dev.
(Reading database … 123647 files and directories currently installed.)
Unpacking libpam0g-dev (from …/libpam0g-dev_0.79-4_i386.deb) …
Setting up libpam0g-dev (0.79-4) …

let’s try to compile again:

pauls@voltaire:~/code/eget/all/pam$ make
gcc  pamexample.c  -o pamexample -lpam -lpam_misc

It works!

Posted in Debian, Ubuntu |

5 Responses

  1. Sirko Says:

    Thanks. It has helped me.

  2. Esben Says:

    auto-apt can also be a cool tool to solve dependencies of precompiled software etc.

  3. arno. Says:

    apt-file is cool !

    another nice thing is command “show” :
    apt-file show package.

    It shows you the files in a package, it’s quit equivalent to dpkg -L but for packages not installed.

    So, you can get some informations about a package without installing it :
    is it a “big” package ?
    does it contains lot of doc ?
    does it contains translations in my language ? and so on.

  4. Roderik Says:

    Wow! I am glad I am following this site because this package has really helped me out just now…

    Thanks a lot! Keep up the good work.

  5. Aljosha Says:

    tnx it also helped to me :)