LinuxCommandLibrary

ldconfig

Update shared library cache

TLDR

Update symlinks and rebuild the cache (usually run when a new library is installed)

$ sudo ldconfig
copy

Update the symlinks for a given directory
$ sudo ldconfig -n [path/to/directory]
copy

Print the libraries in the cache and check whether a given library is present
$ ldconfig [[-p|--print-cache]] | grep [library_name]
copy

SYNOPSIS

ldconfig [OPTIONS]

PARAMETERS

-v
    Verbose mode. Prints the directories being scanned and the links being created.

-n
    Don't rebuild cache. Only creates or updates symbolic links in the specified directories, without updating the cache file.

-N
    Don't rebuild links. Only rebuilds the cache (/etc/ld.so.cache), without creating or updating symbolic links.

-X
    Don't update symbolic links. Similar to -N, it only rebuilds the cache, ignoring link creation.

-r ROOT
    Change root directory. Specifies an alternate ROOT directory to search for libraries, useful in chroot environments.

-p
    Print cache. Displays the contents of the current cache (/etc/ld.so.cache) in a readable format, listing directories and libraries.

-C CACHE
    Specify cache file. Uses CACHE as the cache file instead of the default /etc/ld.so.cache.

-f CONF
    Specify config file. Uses CONF as the configuration file instead of the default /etc/ld.so.conf.

DESCRIPTION

The ldconfig command creates the necessary links and cache (/etc/ld.so.cache) used by the dynamic linker/loader (ld.so or ld-linux.so).

It scans a set of standard directories and directories specified in the configuration file (/etc/ld.so.conf and files in /etc/ld.so.conf.d/) for shared libraries. For each library found, it creates symbolic links to the most recent version of the shared library, ensuring that applications can find and load them correctly.

The generated cache file significantly speeds up application startup by providing a compiled list of available libraries and their locations. This command is typically run by the root user after installing new shared libraries, updating existing ones, or modifying library search paths, to ensure the system's library cache is up-to-date and consistent.

CAVEATS

  • Requires root privileges: The command modifies system-wide files and directories, so it must be run with superuser permissions.
  • Impact on applications: Incorrect usage or failure to run ldconfig after library changes can prevent applications from launching due to missing shared library errors.
  • Cache corruption: Accidental deletion or corruption of the ld.so.cache file can render many system applications unusable until it is rebuilt.

THE SHARED LIBRARY CACHE (<I>/ETC/LD.SO.CACHE</I>)

This binary file is generated by ldconfig and contains a compiled list of shared libraries and their locations. The dynamic linker uses this cache to quickly locate libraries during program execution, significantly reducing load times compared to searching directories every time.

CONFIGURATION FILES (<I>/ETC/LD.SO.CONF</I> AND <I>/ETC/LD.SO.CONF.D/</I>)

These text files define the directories where ldconfig should look for shared libraries. /etc/ld.so.conf often includes all files ending with .conf in the /etc/ld.so.conf.d/ directory, allowing system administrators and package managers to modularly add or remove library search paths without modifying the main configuration file directly.

HISTORY

ldconfig is a foundational utility within the GNU C Library (glibc) on Linux and other Unix-like operating systems. It has been an essential component for managing shared libraries since the widespread adoption of dynamic linking, particularly with the Executable and Linkable Format (ELF). Its stable and critical role ensures efficient resolution of shared library dependencies for applications.

SEE ALSO

ldd(1), ld.so(8), ld(1), dlopen(3)

Copied to clipboard