How to Check if a Library is Installed in Linux: Command Line Methods for libjpeg and Other Libraries


3 views

When working on Linux systems, developers often need to verify whether specific libraries are installed before compiling or running applications. This is particularly important when dealing with dependencies for programming projects or system administration tasks.

The most straightforward way to check for installed libraries is using your distribution's package manager:


# For Debian/Ubuntu systems
dpkg -l | grep libjpeg

# For RHEL/CentOS/Fedora systems
rpm -qa | grep libjpeg

Sometimes you need to verify the actual library files:


# Search for libjpeg files in standard locations
find /usr/lib /usr/local/lib -name "*libjpeg*"

# Check ldconfig cache (for shared libraries)
ldconfig -p | grep libjpeg

For development libraries with pkg-config support:


pkg-config --modversion libjpeg

# If you're not sure about the exact package name:
pkg-config --list-all | grep jpeg

For more thorough checking, you can attempt to compile a simple test program:


#include 
#include 

int main() {
    printf("libjpeg version: %d\n", JPEG_LIB_VERSION);
    return 0;
}

Compile with:


gcc -o jpegtest jpegtest.c -ljpeg

Development environments often need header files:


# Check for jpeglib.h header
find /usr/include -name "jpeglib.h"

For Python projects needing libjpeg:


import sys
from PIL import features
print(features.check_feature('libjpeg_turbo'))

For custom installations or non-standard locations:


# Check LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH

# Use ldd on binaries that should link to libjpeg
ldd /path/to/your/binary | grep libjpeg

When working on Linux systems, developers often need to verify whether specific libraries are installed before compiling or running applications. This is particularly important for dependencies like libjpeg, which is commonly used for image processing. Here are several reliable methods to check library installation from the command line.

The ldconfig command is one of the most straightforward ways to check for installed libraries:

ldconfig -p | grep libjpeg

If libjpeg is installed, this will return output like:

libjpeg.so.8 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libjpeg.so.8

For systems using apt (Debian/Ubuntu):

dpkg -l | grep libjpeg

Or more specifically:

dpkg -l libjpeg*

For RPM-based systems (RedHat/CentOS):

rpm -qa | grep jpeg

You can search for the library files directly:

find /usr/lib -name "*jpeg*" -type f

Or check standard library paths:

ls /usr/lib | grep jpeg

For development purposes, pkg-config is often more useful:

pkg-config --modversion libjpeg

This will return the version number if installed, or an error if not found.

For the most thorough check, try compiling a simple test program:

echo -e '#include <stdio.h>\n#include <jpeglib.h>\nint main(){return 0;}' > test.c
gcc test.c -o test -ljpeg

If compilation succeeds, the library is properly installed.

Development headers can be checked separately:

find /usr/include -name jpeglib.h

Some systems provide specialized tools:

apt-file search libjpeg.so  # Requires apt-file installed
yum provides */libjpeg.so   # For yum-based systems