ldconfig Command

The ldconfig command configures the dynamic linker run-time bindings by creating a cache of shared libraries. This cache speeds up program loading by providing quick access to library locations.

Syntax

ldconfig [OPTIONS] [DIRECTORIES...]

Description

The ldconfig command creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib).

Key functions:

  • Creates symbolic links for shared libraries
  • Updates the library cache (/etc/ld.so.cache)
  • Configures library search paths
  • Resolves library dependencies
  • Improves program startup performance
Note: ldconfig is typically run automatically during system boot and package installation, but manual execution may be needed after installing custom libraries.

Common Options

Option Description
-v, --verbose Verbose mode, display libraries being processed
-n Process only directories specified on command line
-N Don't rebuild cache, only process symbolic links
-X Don't update symbolic links
-f CONF Use CONF instead of /etc/ld.so.conf
-C CACHE Use CACHE instead of /etc/ld.so.cache
-r ROOT Change to and use ROOT as root directory
-l Library mode, manually link individual libraries
-p, --print-cache Print current cache contents
-i, --ignore-aux-cache Ignore auxiliary cache file

Examples

Update library cache

sudo ldconfig

Updates the shared library cache with default settings

Verbose cache update

sudo ldconfig -v

Updates cache and shows which libraries are being processed

Print current cache contents

ldconfig -p

Displays all libraries currently in the cache

Search for specific library in cache

ldconfig -p | grep libssl

Shows SSL library entries in the cache

Process specific directory

sudo ldconfig -v /usr/local/lib

Updates cache for libraries in /usr/local/lib directory

Process only command line directories

sudo ldconfig -n /opt/myapp/lib

Processes only the specified directory, ignoring config files

Update links without rebuilding cache

sudo ldconfig -N

Updates symbolic links but doesn't rebuild the cache

Use custom configuration file

sudo ldconfig -f /etc/ld.so.conf.custom

Uses a custom configuration file instead of the default

Manual library linking

sudo ldconfig -l /usr/local/lib/libmylib.so.1.0

Manually creates symbolic links for a specific library

Check library dependencies

ldd /usr/bin/program sudo ldconfig ldd /usr/bin/program

Checks dependencies before and after updating cache

Configuration Files

/etc/ld.so.conf

# Main configuration file include /etc/ld.so.conf.d/*.conf /usr/local/lib /opt/lib

Main configuration file specifying library search paths

/etc/ld.so.conf.d/custom.conf

# Custom library paths /opt/myapp/lib /usr/local/custom/lib

Custom configuration file for additional library paths

Add new library path

echo "/opt/newapp/lib" | sudo tee /etc/ld.so.conf.d/newapp.conf sudo ldconfig

Adds a new library path and updates the cache

Troubleshooting Library Issues

Fix "shared library not found" error

# Check if library exists find /usr -name "libmissing.so*" 2>/dev/null # Add library path if found echo "/path/to/library" | sudo tee /etc/ld.so.conf.d/custom.conf sudo ldconfig # Verify library is cached ldconfig -p | grep libmissing

Steps to resolve missing shared library errors

Rebuild cache after library installation

# After installing libraries manually sudo cp libmylib.so.1.0 /usr/local/lib/ sudo ln -sf /usr/local/lib/libmylib.so.1.0 /usr/local/lib/libmylib.so.1 sudo ln -sf /usr/local/lib/libmylib.so.1 /usr/local/lib/libmylib.so sudo ldconfig

Proper steps after manual library installation

Check library conflicts

ldconfig -p | grep libconflict | sort

Identifies multiple versions of the same library

Verify library loading

LD_DEBUG=libs program_name 2>&1 | grep library_name

Debug library loading for a specific program

Best Practices

Library Management Best Practices
  • Regular Updates - Run ldconfig after installing new libraries
  • Organized Paths - Use /etc/ld.so.conf.d/ for custom library paths
  • Version Management - Maintain proper symbolic links for library versions
  • Testing - Verify library loading after configuration changes
  • Documentation - Document custom library installations and paths

Related Environment Variables

Variable Description Example
LD_LIBRARY_PATH Runtime library search path export LD_LIBRARY_PATH=/opt/lib:$LD_LIBRARY_PATH
LD_PRELOAD Libraries to load before others export LD_PRELOAD=/path/to/lib.so
LD_DEBUG Debug dynamic linker LD_DEBUG=libs program

Common Use Cases

When to Use ldconfig
  • After Library Installation - Update cache after installing new shared libraries
  • Custom Software - Configure paths for locally compiled software
  • System Maintenance - Fix broken library dependencies
  • Development - Manage development library versions
  • Troubleshooting - Resolve "library not found" errors

See also