Linux: Set OR Change The Library Path

I‘ve compile and installed a library at /usr/local/lib/ -> How do I set the Library path under Linux operating systems?

You need to use ldconfig config file and ldconfig command which 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/, and in the trusted directories such as /lib64 or /usr/lib64 (/lib or /usr/lib on 32 bit systems).
Tutorial details
Difficulty level Intermediate
Root privileges Yes
Requirements GNU gcc
Est. reading time 10m
The /etc/ contains lib settings which can be used to add or delete paths. However, you need to simply drop your config file in /etc/ directory and it will be used by /sbin/ldconfig to configure dynamic linker run time bindings.

Add Your Path

Create a file called /etc/
# vi /etc/
Add the following path:


Save and close the file.

Activate Your Library Path

You must run the following command to activate path:
# ldconfig

Verify Your New Library Path

# ldconfig -v | less
# ldconfig -v | grep /usr/local/lib
Sample outputs:

/usr/local/lib: -> ->
/usr/lib64/mysql: -> ->
/lib: ->

How Do I Delete The Library Path?

Simply, delete the file:
# rm /etc/
# ldconfig

How Do I Edit The Library Path?

Simply edit the file and reload the changes:
# vi /etc/
# ldconfig

How Do I Compile Program With Shared Libs And GNU GCC?

You can use the following gcc
$ gcc -Wl,-R/path/to/lib -I/path/to/include -L/path/to/lib -o myAppName mycode.c -llibapp2
See gcc man page for further details.

Further readings:

man ldconfig man ld man gcc

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Michael Apr 11, 2010 @ 18:45

    Great article.
    Unfortunately in Fedora 12 the (local) manual page of ldconfig is missing :-(

  • Vijay Kanta Aug 11, 2013 @ 11:56

    You don’t cease to amaze me Vivek. Great article to keep my Linux journey going.

  • Anil Sep 17, 2013 @ 23:41

    Great information…
    Thanks a lot.

  • peltouze Jan 7, 2016 @ 14:00

    Old thread but still, I’ll try.
    Can’t we just add any path to LD_LIBRARY_PATH environment variable ?
    (I’m working on a system on which I don’t have root privileges…)

  • Diego Amicabile Aug 16, 2017 @ 11:34

    You are my hero

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum