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/ Configuration File

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

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 -?


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/ .

1052 libs found in cache `/etc/' (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/ (libc6,x86-64) => /lib/x86_64-linux-gnu/

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/ -> -> -> -> -> ->

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/” file and then run the ldconfig like below.


Leave a Comment