How to find and install packages contaning missing files and libraries in Debian, Ubuntu, Fedora, CentOS, RHEL Linux with apt-file

Tuesday, 19th January 2010

apt-file-how-to-find-and-install-missing-header-and-files-libraries-belonging-to-which-Debian-Ubuntu-centos-fedora-rhel-linux-package-management

Every now and then we need to look up for specific files such as development C header files .h, or lib.so library files as we download some already compiled libraries or just for the sake of properly compiling a brand new free software that is available only as a source code but we end up with missing file dependencies.

That is pretty common in the world of Free Software GNU / Linux and of course it is really annoying to google like crazy to determine which .deb package (if there is existing such) is including the missing header file, library or binary.
I assume many people had end up in this scenario and luckily the developers in most GNU / Linux distributions realized about this potential issue and decided to save time to people for the Googling and included tools to be able to determine if a specific file is part of any installable distribution package or not.

So how to look up for missing header files, libraries and dependencies which are not easy to determine based on the package name?

If you still don't have idea of what I'm talking about here is a little example to illustrate what I mean:

Lets say you need to look up for file libnet.h:

libnet.h


Debian has a develpoed perl scrit called apt-file that once after installed can be used to do a queries to determine whether a specific needed file is part of an installable package, before we start we need to install apt-file tool.

Do it the normal way with apt-get, e.g.:

 

noah:/home/hipo# apt-get install apt-file

 


Now as apt-file is installed in order to update its database isssue commands:
 

 

 

noah:/home/hipo# apt-file update

Downloading Index http://ftp.bg.debian.org/debian/dists/unstable/Contents-amd64.diff/Index: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed102 2053 102 2053 0 0 23458 0 –:–:– –:–:– –:–:– 111k
Calculating old sha1sum…File is up-to-date.Ignoring source without Contents File: http://dl.google.com/linux/deb/dists/stable/Contents-amd64.gz

 

 

noah:/home/hipo# apt-file search libnet.h

libaudio-dev: /usr/include/audio/Alibnet.hlibnet1-dev: /usr/include/libnet.hlibnet1-dev: /usr/share/man/man3/libnet.h.3.gzAnd there we go, Now I know that libnet.h is included in libnet1-dev package, and therefore can


install it with:

 

noah:/home/hipo# apt-get install libnet1-dev

 

So far so good but what about Linux users and sysadmins that need to look up for packages containing specific development header, library, script or binary belongs where on Fedora, CentOS, RHEL Linux?

Lets assume you're on an RPM based Linux distribution and you happen to be missing a library file:
 

ld-linux.so.2

 


and you have just downloaded a precompiled binary file and you desperately need to have above mentioned library to be able to run the binary.

Use yum tool to determine the file belonging to which package:
 

 

 

yum provides ld-linux.so.2

Command will produce you output to something like:

Loaded plugins: langpacks, presto, refresh-packagekit
Adding en_US to language list
glibc-2.12.90-17.i686 : The GNU libc libraries
Repo        : fedora
Matched from:
Other       : ld-linux.so.2

glibc-2.12.90-21.i686 : The GNU libc libraries
Repo        : updates
Matched from:
Other       : ld-linux.so.2

yum provides */unistd.h
this will list every package containing “unistd.h”

Use it as many times you need for as many files necessery and Enjoy life 🙂

 

Share this on:

Download PDFDownload PDF

Tags: , ,

Leave a Reply

CommentLuv badge