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 [-v] [-p] [-n] [-N] [-X] [-f conf] [-C cache] [-r root] [directory ...]

PARAMETERS

-v, --verbose
    Print actions performed, like creating links or adding cache entries.

-p, --print-cache
    Display contents of current ld.so.cache without updating.

-n
    Process directories but do not create symbolic links.

-N
    Do not canonicalize paths or update ld.so.cache.

-X
    Do not generate links for libraries (only update cache).

-f conf
    Use alternate config file instead of /etc/ld.so.conf.

-C cache
    Write cache to specified file instead of /etc/ld.so.cache.

-r root
    Set root directory for operations (chroots).

directory ...
    Scan these directories for libraries, appending to config.

DESCRIPTION

ldconfig is a key Linux utility for managing the dynamic linker's runtime bindings. It scans directories listed in /etc/ld.so.conf and /etc/ld.so.conf.d/ files to locate shared object libraries (.so files). The tool then:

  • Creates symbolic links for libraries with sonames to their actual files.
  • Generates or updates the cache file /etc/ld.so.cache, enabling fast lookups by the dynamic linker (ld.so).

This cache avoids scanning library directories at every program launch, improving performance.

Invoked automatically by package managers (e.g., after rpm or dpkg installs), or manually by root when adding libraries to new directories. Without arguments, it processes the default config. Specifying directories overrides or appends to the config.

Common use: After copying libs to /usr/local/lib, run ldconfig to integrate them system-wide. Verbose mode aids debugging library paths.

Essential for 32/64-bit multi-arch systems, handling hardware capabilities (hwcap) directories like /lib64. Misuse risks system breakage if cache corrupts.

CAVEATS

Requires root privileges (or CAP_SYS_ADMIN) to update cache/links. Errors in config can prevent programs from finding libraries, breaking applications. Always backup /etc/ld.so.cache before manual runs. Not for static linking.

COMMON USAGE

ldconfig -p | grep libc -- List libc libraries.
echo '/opt/mylib' >> /etc/ld.so.conf && ldconfig -- Add directory.

MULTI-ARCH NOTE

Handles /lib/i386-linux-gnu/, /lib/x86_64-linux-gnu/; use dpkg --add-architecture for cross-arch setups.

HISTORY

Developed as part of GNU C library (glibc) in early 1990s for Linux ELF dynamic linking support. Evolved with multi-arch (i386/x86_64) and hwcap features in glibc 2.0+. Standard in all major distros since kernel 2.x era.

SEE ALSO

ldd(1), ld.so(8), ld(1), ldconfig(8)

Copied to clipboard