How can I re-order LD_LIBRARY_PATH?


I'm interested in LD_LIBRARY_PATH because I have this problem:

I can't update, upgrade and remove my app from kubuntu

and one of the error is due to libreadline.so, but how I explaind here: https://dba.stackexchange.com/questions/31143/libreadline-so-6 it is important for postgresql.

In a comment Phil said to me:

You can probably fix this by re-ordering your LD_LIBRARY_PATH so that /usr/local/lib/ is >at the end, rather than the beginning.

  • 2
    How is it currently being set? Dec 29, 2012 at 11:20
  • 1
    I recommend against closing this. While a better answer could be given if more information is provided, currently this is answerable, and I think my answer could help other users as well. Dec 29, 2012 at 19:44
  • Your question would be better and easier to answer if you motivate why you would like to reorder it and how you set it?
    – N.N.
    Dec 29, 2012 at 19:53

1 Answer 1


To expand on the idea in Ignacio Vazquez-Abrams's comment: It would be helpful find out how the current value of this environment variable (with the order you don't like) is being set, in order to change it.

If you have no idea how it's being set, run:

grep LD_LIBRARY_PATH= ~/.* /etc/*

That will look at all the dotfiles in your home directory and all the top-level files in /etc. You'll get permission denied messages from the query but that's fine, they won't be for places that are at all likely to contain a script that runs and sets LD_LIBRARY_PATH. (So you do not need to run that querying command as root.)

If you only get permission denied messages, then nothing was found. If you also have lines with a filename, a colon, and contents of the file, then it was found that that might be where it's being set. It also might not be.

You can expand your query by removing the = character; just be aware you're more likely to have false positives, where the variable is being used but not being set.

If that fails...

If you still cannot find it, you can try setting the variable yourself. See:

If it gets set after it's set by whatever mechanisms are currently doing it, you can replace its value with whatever you want (and that can be a reordered version of what it currently is).

If you try this and it either does nothing or you find it contains the text you gave it, with other text before or after it (or some before and some after), then at least this will give you information about when it's being set, compared to when it gets set by whatever method you choose to use.

If text in the wrong order is tacked on just to the end of the variable as you set it, that's annoying but it's equivalent so long as all the same directories are part of your previously ordered path. (All that matters is where a directory first appears in the path, because after it's not matched there, it won't be matched anywhere else either.)

If you can provide more information about why you need to do this, that might make it easier to figure out better ways of discovering what is currently setting it, and that might make it possible for a suggestion to be made about how best to set it yourself.

This answer applies to other environment variables, too.

But, for some variables, like PATH, there are a few places that almost always set it, so a similar problem with that might be easier to solve.

  • Thank you for your answer, I haven't tryed yet, but I feel that is pretty exhaustive.
    – DarkCoffee
    Dec 30, 2012 at 6:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .