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
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
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
Updates the shared library cache with default settings
Verbose cache update
Updates cache and shows which libraries are being processed
Print current cache contents
Displays all libraries currently in the cache
Search for specific library in cache
Shows SSL library entries in the cache
Process specific directory
Updates cache for libraries in /usr/local/lib directory
Process only command line directories
Processes only the specified directory, ignoring config files
Update links without rebuilding cache
Updates symbolic links but doesn't rebuild the cache
Use custom configuration file
Uses a custom configuration file instead of the default
Manual library linking
Manually creates symbolic links for a specific library
Check library dependencies
Checks dependencies before and after updating cache
Configuration Files
/etc/ld.so.conf
Main configuration file specifying library search paths
/etc/ld.so.conf.d/custom.conf
Custom configuration file for additional library paths
Add new library path
Adds a new library path and updates the cache
Troubleshooting Library Issues
Fix "shared library not found" error
Steps to resolve missing shared library errors
Rebuild cache after library installation
Proper steps after manual library installation
Check library conflicts
Identifies multiple versions of the same library
Verify library loading
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