This question already has an answer here:

I am running Debian. I have a jar file that I need to execute. A wrapper bash script does a java -jar MyProg.jar. The jar also calls some C code for which LD_LIBRARY_PATH needs to be set.

I have set LD_LIBRARY_PATH in the current user's (let's say Sriram)'s bashrc like so: export LD_LIBRARY_PATH=myLibLocation.

Everything works as expected when running the above script from the command line. However, when I run the same bash file by double-clicking on it, LD_LIBRARY_PATH is not set. Here is a sample bash script I wrote:

echo `whoami`;
echo "PATH = ${LD_LIBRARY_PATH}"  

It runs as expected from the command line but not when I run it by double-clicking. The output in that case is:

PATH =   

This question is exactly the same as this. I have tried to implement all the suggestions there but have not had success.


What I tried from the answer to the question I linked to:
1. Created a file ~/.xsessionrc. It did not exist on my system.
2. Set LD_LIBRARY_PATH in the above script.

Restarted a new shell. Re-ran the above script. No changes were observed.

Any help is most welcome.

marked as duplicate by Gilles bash Jun 3 '15 at 21:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Can you show/explain what you have implemented from the similar question/answer because it should have worked. – X Tian Jun 3 '15 at 9:42
  • @XTian: Added more information. – Sriram Jun 3 '15 at 13:10
  • Just a detail but... why would you do echo `whoami`; instead of just whoami? – Celada Jun 3 '15 at 14:51
  • @Celada: It might echo "whoami" rather than the currently signed in user name. I wanted the result of that command echoed to see what user is executing the script (Nautilus or me). – Sriram Jun 3 '15 at 15:58
  • Environment variables go into .profile, not .bashrc. The problem you're observing is the main reason not to define environment variables in .bashrc. – Gilles Jun 3 '15 at 21:27

Try this (you're missing a '#!' and it's also usually better to set program-specific environment in that program's wrapper script rather than ~/.bashrc to not potentially affect other programs):

export LD_LIBRARY_PATH=myLibLocation
echo `whoami`;
echo "PATH = ${LD_LIBRARY_PATH}"  
  • Thanks, but in the script these have been added. That must have been a typo. – Sriram Jun 3 '15 at 13:40
  • Exporting LD_LIBRARY_PATH works as you suggest. I am looking for a more permanent solution like appending that path to the bashrc etc. – Sriram Jun 3 '15 at 16:04

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