Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In linux, how do I check if a library is installed or not? (from the command line of course).

In my specific case now, I want to check whether libjpeg is installed.

share|improve this question
What distribution are you using ? – radius Aug 16 '09 at 16:09

To do this in a distro-independent* fashion you can use ldconfig with grep, like this:

ldconfig -p | grep libjpeg

If libjpeg is not installed, there will be no output. If it is installed, you will get a line for each version available.

Replace libjpeg by any library you want, and you have a generic, distro-independent* way of checking for library availability.

*99% of the times

share|improve this answer
Better than locate! – digz6666 Nov 11 '13 at 3:07
This should be accepted as the answer. Great! – user105523 Dec 19 '13 at 13:53
Except for NixOS :-( – iElectric Apr 16 '15 at 18:34
It's not possible to use this for checking for the dev version (headers) of a library, right? – andig Aug 14 '15 at 8:08
@andig for that you my try something like "find /usr/include/ -iname *jpeg*". – faken Aug 14 '15 at 8:26

You can check with the package manager of your distribution (aptitude, yum, ...) but as you did not give your distribution I can't give you the right command.

Another way can be to run gcc -ljpeg, if you get 'ld: library not found for -ljpeg' it means that gcc has not found the library (but it don't mean that it's not installed), if you get something like 'Undefined symbols: "_main", referenced from: ...' it means that libjpeg has been found.

locate libjpeg; ls /usr/lib/libjpeg*; ls /lib/libjpeg* are some other way to find if the lib in installed in the system

There is many other way to check that, if you give us more context (why you need to check if libjpeg is installed) we could give you the best solution for your specific case.

share|improve this answer
How to find it using aptitude? – BBK Apr 3 '12 at 5:52

I'm use whereis utility.

l1feh4ck3r@xxx:~$ whereis libjpeg
libjpeg: /usr/lib/ /usr/lib/libjpeg.a /usr/lib/
share|improve this answer

For deb-based distribution you can do

dpkg -s packagename

Or if you know the filename only, use

locate filename

The filename is usually[.version].

share|improve this answer
The filename can also be something like "libsomething.a" for static version. – radius Aug 16 '09 at 16:40
I find dpkg -s limited in utility, because it wants the actual package name, which may differ subtly or significantly from the library itself. I use dpkg -s|grep LIBRARY – Drew Stephens Aug 16 '09 at 16:41
@dinomite apt-file is your friend :) – radius Aug 16 '09 at 16:50

This is done by configuration tools on linux all the time.

Look at this Tutorial about autoconf and KDevelop.

Other tricks would use commands like ldconfig and dpkg.

share|improve this answer

On Redhat based systems, one can use pkg-config to verify if a library is installed or not. Many rpm binaries actually make the same checks before proceeding with installation, so we can reasonably rely on its veracity.

pkg-config --cflags jpeg

pkg-config --libs jpeg

pkg-config --cflags "jpeg >= 1.0.0" # for version check
pkg-config  --modversion jpeg | awk -F. '{ printf "0x%02X%02X%02X\n",$1,$2,$3 }' #version check
share|improve this answer

I use this:

gcc -lpng

When the lib is installed, it yields:

undefined reference to 'main'

When the lib is not installed:

cannot find -lpng
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.