How to check if a library is installed?

Solution 1:

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.

If for some reason the path to ldconfig is not set, you can try to invoke it using its full path, usually /sbin/ldconfig.

**99% of the times*

Solution 2:

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.


Solution 3:

I use the whereis utility.

Sample:

l1feh4ck3r@xxx:~$ whereis libjpeg
libjpeg: /usr/lib/libjpeg.so /usr/lib/libjpeg.a /usr/lib/libjpeg.la

Solution 4:

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

Solution 5:

For deb-based distribution you can do

dpkg -s packagename

Or if you know the filename only, use

locate filename

The filename is usually libsomething.so[.version].