pls see the update below

My bashrc has the line . ./bash_path_vars, where bash_path_vars contains:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

But what I get in the new terminal is:



If you put that export statement directly inside bashrc, there is no duplication!

I am puzzled. Why does this happen?

UPDATE: I am stupid, I had . ./bash_path_vars two times in two different places. Of course, it resulted in duplication... Thanks to every one who replied to this question and sorry for not asking a better question!

  • put it this way: export LD_LIBRARY_PATH=/usr/local/lib, then export PATH=$LD_LIBRARY_PATH:$PATH – George Udosen Mar 7 '17 at 11:03
  • Please post the entry for .bash_paths as entered in .bashrc – George Udosen Mar 7 '17 at 17:09
  • BTW, you should probably change ./bash_path_vars to ~/bash_path_vars to avoid issues when restarting the shell outside of $HOME. – wjandrea Mar 8 '17 at 5:18
  • I just tried a setup like yours (with the path file and source statement in bashrc), and got duplication! It was because I already exported the variable and restarted the shell (exec bash), so it inherited the variables from the last shell, instead of starting fresh. Try logging out and back in, which will end all current shell sessions. – wjandrea Mar 8 '17 at 5:23
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

This command does not just set or overwrite LD_LIBRARY_PATH, but rather takes the existing variable and expands it with :/usr/local/lib

Take a look at .bash_profile and /etc/profile, whether the variable is also set there. You could also set:

export LD_LIBRARY_PATH=:/usr/local/lib  

in bashrc.

  • yes, I am aware that the command just appends to LD_LIBRARY_PATH --- that is intended. No, LD_LIBRARY_PATH is not set anywhere else (I also tried to use some funny path instead of /usr/local/lib --- the same effect, it gets duplicated). Don't you get the duplication on your machine? – Ayrat Mar 7 '17 at 10:28

Your are doing it wrongly. Please note that $LD_LIBRARY_PATH is already a variable declared some where, so when you do:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

You are saying, expand $LD_LIBRARY_PATH, and add /usr/local/lib so you will get what your currently seeing:


Now change your entry in the .bashrc file to:

export LD_LIBRARY_PATH=/usr/local/lib

Now when you run: echo $LD_LIBRARY_PATH, you should see /usr/local/lib

Merely putting: export LD_LIBRARY_PATH=/usr/local/lib will give you the desired result, but adding the second line (export PATH=$LD_LIBRARY_PATH:$PATH) puts that variable in your system path.

  • sorry, not clear, why do I get duplication? (yes, I want to expand the old value of LD_LIBRARY_PATH (which does not have /usr/...), and then append a new entry to it). Thanks! – Ayrat Mar 7 '17 at 15:12
  • The reason is simple you have export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib, in there you have two declarations of /usr/local/lib. One plane /usr/local/lib, and another represented as $LD_LIBRARY_PATH is link when you use 1 += 1. You are simply adding /usr/local/lib unto itself – George Udosen Mar 7 '17 at 15:28
  • Please be more explicit, what do you mean by /user/...? Give an example... – George Udosen Mar 7 '17 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.