Linux ldconfig Command Tutorial

Linux commands and executables heavily rely on shared libraries where a single shared library is generally used by multiple commands or executables even by other libraries. A shared library is a file that contains binary code in order to run Linux commands and executables properly. The shared means that the library can be used by others easily without a problem. The ldconfig command is used to created required links and cache and manage them.

/etc/ld.so.conf Configuration File

The main configuration file for the ldconfig command is the /etc/ld.so.conf file. This configuration file contains shared library configurations or provides a link to the other shared library configurations which are located under the “/etc/ld.so.conf.d/“.

Print Help Information about ldconfig Command

Even it is not complex command the help information and options about the ldconfig command can be listed with the –help option like below.

ldconfig --help

Help information is like below.

Usage: ldconfig.real [OPTION…]
 Configure Dynamic Linker Run Time Bindings.
 -c, --format=FORMAT        Format to use: new (default), old, or compat
   -C CACHE                   Use CACHE as cache file
   -f CONF                    Use CONF as configuration file
   -i, --ignore-aux-cache     Ignore auxiliary cache file
   -l                         Manually link individual libraries.
   -n                         Only process directories specified on the command
                              line.  Don't build cache.
   -N                         Don't build cache
   -p, --print-cache          Print cache
   -r ROOT                    Change to and use ROOT as root directory
   -v, --verbose              Generate verbose messages
   -X                         Don't update symbolic links
   -?, --help                 Give this help list
       --usage                Give a short usage message
   -V, --version              Print program version

Alternatively the -? or –usage option can be used to print help information.

ldconfig -?

or

ldconfig --usage

List Cached Libraries

The ldconfig command can be used to list already cached library files. The -p option should be provided into the ldconfig command.

ldconfig -p

The output is like below. From the output we can see that total 1052 libraries found. The library names and paths are listed in this output. All of these information is provided and stored in the /etc/ld.so.cache .

1052 libs found in cache `/etc/ld.so.cache'
     libzvbi.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libzvbi.so.0
     libzvbi-chains.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libzvbi-chains.so.0
     libzstd.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libzstd.so.1
     libzmq.so.5 (libc6,x86-64) => /lib/x86_64-linux-gnu/libzmq.so.5
     libzephyr.so.4 (libc6,x86-64) => /lib/x86_64-linux-gnu/libzephyr.so.4
     libzbar.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libzbar.so.0
     libz.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libz.so.1
     libz.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libz.so
     libyelp.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libyelp.so.0
     libyaml-0.so.2 (libc6,x86-64) => /lib/x86_64-linux-gnu/libyaml-0.so.2
     libyajl.so.2 (libc6,x86-64) => /lib/x86_64-linux-gnu/libyajl.so.2
     libx265.so.192 (libc6,x86-64) => /lib/x86_64-linux-gnu/libx265.so.192
     libx264.so.160 (libc6,x86-64) => /lib/x86_64-linux-gnu/libx264.so.160

List All Libraries and Their Directories

The -v option can be used to scan all directories for libraries and print the library name and library file. Also, the library configuration file is listed too.

ldconfig -v

The output is like below.

/lib/x86_64-linux-gnu: (from /etc/ld.so.conf.d/x86_64-linux-gnu.conf:3)
     libnetplan.so.0.0 -> libnetplan.so.0.0
     libnssutil3.so -> libnssutil3.so
     libboost_iostreams.so.1.71.0 -> libboost_iostreams.so.1.71.0
     libcupsimage.so.2 -> libcupsimage.so.2
     libgtop-2.0.so.11 -> libgtop-2.0.so.11.0.1
     libunwind-coredump.so.0 -> libunwind-coredump.so.0.0.0

Add New Library

When you want to add a new library the -n option can be used. With the -n option the library path or directory should be provided. A new library can be added when you have compiled a source code into the library or download a library from the internet. In the following example, we will add the path “/opt/lib” as a new library path where all libraries under this directory are automatically added.

ldconfig -n /opt/lib

An alternative way to add a new library or library path is to put the library path into the “/etc/ld.so.conf” file and then run the ldconfig like below.

ldconfig
READ  How To List Services with systemctl list Command?

Leave a Comment