14

This question already has an answer here:

I'm trying to change the value of $JAVA_HOME & I just can't seem to find in which file is it being set currently. I can't remember where did I set it the last time. Already tried How to determine where an environment variable came from? but I need(ed) a list of files where the variable can be set.

marked as duplicate by Braiam, Networker, Anthon, garethTheRed, Michael Homer Sep 11 '14 at 7:24

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.

29

You didn't specify a shell. So, I will assume bash. The next issue is: did you set it for your user only or system-wide? If you set it for your user only, then run:

grep JAVA_HOME  ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc

If you set it system-wide, then it may vary with distribution but try:

grep JAVA_HOME /etc/environment /etc/bash.bashrc /etc/profile.d/* /etc/profile

If the above give no answer, you can cast a wider net:

grep -r JAVA_HOME /etc
grep -r JAVA_HOME ~/

See also the suggestions in How to determine where an environment variable came from.

  • Thank you for responding. Couldn't find this variable in any of these files. Btw, I'm on Ubuntu (if that matters) – mindreader Sep 11 '14 at 5:29
  • For clues, please check (a) if you log in as a different user, is JAVA_HOME still set? (b) If you reboot, is it still set? This search can be complicated because any of the files I listed can source other files of their choosing and JAVA_HOME could be set in any of those. – John1024 Sep 11 '14 at 5:39
  • Sorry, my bad.. I had set it in ~/.bashsrc but the changes didn't show up since I used different terminal instances to set & test the value of variables. Thanks for your help. – mindreader Sep 11 '14 at 5:43
8

With zsh:

zsh -xl

In bash:

PS4='+$BASH_SOURCE> ' BASH_XTRACEFD=7 bash -xl 7>&2

That will simulate a login shell and show everything that is done (except in areas where stderr is redirected with zsh) along with the name of the file currently being interpreted.

So all you need to do is look for JAVA_HOME in that output. (you can use the script command to help you store that output).

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