How to change the path of shared libraries shown by ldd

dynamic-linkinglibrariespostgresqlshared library

I am trying to make the postgis extension work on my system and it always spits out "$libdir/postgis2.2" no such file or directory error. For my curiosity I executed "ldd postgis-2.2.so" and it spits out the following result :

    linux-vdso.so.1 =>  (0x00007ffff3bc8000)
    /usr/lib64/libjemalloc.so.1 (0x00002b3fe5ff4000)
    libgeos_c.so.1 => not found
    libproj.so.9 => not found
    libjson-c.so.2 => not found
    libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00002b3fe6237000)
    libm.so.6 => /lib64/libm.so.6 (0x00002b3fe659e000)
    libc.so.6 => /lib64/libc.so.6 (0x00002b3fe689c000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b3fe6c41000)
    /lib64/ld-linux-x86-64.so.2 (0x00002b3fe5b2e000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00002b3fe6e5d000)
    libz.so.1 => /lib64/libz.so.1 (0x00002b3fe7061000)
    liblzma.so.5 => /usr/lib64/liblzma.so.5 (0x00002b3fe7277000)

And for a bunch of dependencies I see the path to their so is not present. This I guess is happening because I am not building postgis but just copying the required so's and libs to make it work manually. But I do know the path to those so files that are required by postgis. What should I do such that I can change the "not found" in dependencies to the required path by postgis?

Best Answer

ld.so, the dynamic linker, will use the PATH-like environment variable LD_LIBRARY_PATH when it looks for shared libraries to link at execution time.

You may set LD_LIBRARY_PATH to a :-delimited list of directories where the linker should look for libraries, for example:

$ env LD_LIBRARY_PATH="$HOME/local/lib:/opt/other/lib" ./myprog

See the ld.so manual on your system for more information.

Related Question