44

I am trying to purge the ldconfig cache of links to libraries to link against. I have a local folder where newly built libraries are placed. I want to update the ldconfig cache to point to these newly built libs.

I have tried using the ldconfig -c command, giving it my own .conf file. I also tried replacing the /etc/ld.so.conf file to point to the new path of libs. But even after doing this, when I check the cache using the ldconfig -p command , it is still showing the old libs.

Hence how to purge and rebuild the ldconfig cache? Just to add : I am on Ubuntu 13.10.

eminemence
  • 721
  • 1
  • 6
  • 21

3 Answers3

62

2 years late, but in case someone stumble upon this, as su (not as sudo), run the following commands:

rm /etc/ld.so.cache
ldconfig
codenamezero
  • 2,724
  • 29
  • 64
  • Didn't seem to work for me: I did the above actions, however I still had to wait on the next reboot while `Rebuild Dynamic Linker Cache...` – Hi-Angel Oct 15 '19 at 06:47
  • after `rm /etc/ld.so.cache`, exec sudo report "sudo: error while loading shared libraries: libaudit.so.1" – Crawl.W Jul 08 '21 at 12:39
  • @Crawl.W I did mentioned in my answer to run it **as** `su` didn't I? – codenamezero Jul 08 '21 at 18:32
  • 1
    I exec `sudo rm /etc/ld.so.cache`. – Crawl.W Jul 12 '21 at 11:50
  • Being **su** is slightly different than running the command using **sudo**. I am assuming that you got the "loading shared libraries" error when you try to run the second command `ldconfig`? Or perhaps different distro had done thing differently nowadays. But at the time when I posted the answer, that's what I needed to do to get things working for me. – codenamezero Jul 14 '21 at 19:06
20

Rebuild cache

Open the /etc/ld.so.conf as sudo and add a new line with the library directory. In this case, we add /usr/local/lib. Rerun ldconfig to rebuild the cache:

$ sudo ldconfig

This worked for me.

Karthik M
  • 313
  • 2
  • 6
  • The `/usr/local/lib` was already there, I just had to run the `ldconfig` command so the new libraries would be found. Interestingly enough, it's not available to a regular user. Without `sudo`, it says it doesn't know of `ldconfig`. – Alexis Wilke Mar 10 '22 at 01:52
  • @AlexisWilke Making ldconfig available to a regular user would take the fun out of trying to obtain privilege escalation. If you mull over it a little longer you'll realise (I'm sure you have by now) it would form an unnecessary security risk. – GuyB Oct 25 '22 at 15:43
  • @GuyB, many tools, such as `iptables`, are accessible to a regular user. Then they tell you it could not gain enough permissions to run the command. In that sense, I think it is strange that `ldconfig` is hidden in such a way. – Alexis Wilke Oct 25 '22 at 16:57
  • 1
    @AlexisWilke Ok, I see, you were referring to the visibility per se, not permission. The visibility is determined by the PATH environment variable and the default at install time depends on the distribution. Some distros do not put certain sbin/ paths in PATH for non-root users. iptables (a link to xtables-legacy-multi) and ldconfig might sit in different sbin/ directories, again depending on distro. I use Mageia and they are both visible to ordinary users. – GuyB Oct 31 '22 at 10:34
3

I solved the problem by doing the following:

$ > /etc/ld.so.cache

then:

$ ldconfig

Rastalamm
  • 1,712
  • 3
  • 23
  • 32
Alexmaister
  • 131
  • 1