Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am getitng something weird in my environment.

I have a .bash_profile that only checks for .bashrc and then sources it. I have a JAVA_HOME in that file that is correctly setting the variable and exporting it. However, if I comment out the JAVA_HOME line in .bashrc, another JAVA_HOME is still showing up in my environment, different from the one I was setting in .bashrc. Where is this other JAVA_HOME coming from?

Also, it seems like any shell I run—csh, sh, bash, etc…—is pulling in a JAVA_HOME from somewhere. I dont know what could be making this pull into csh, sh, bash, etc…

share|improve this question
up vote 0 down vote accepted

/etc/profile is the most common

share|improve this answer
    
If not /etc/profile, could be ~/.bash_profile, ~/.bash_login, or ~/.profile. When you login, bash looks for each of these files in the order shown. – fpmurphy1 Apr 15 '12 at 16:59

Bash follows Posix conventions and on startup first sets your shell context by sourcing the /etc/profile file. On RedHat systems, the /etc/profile file contains code to look into /etc/profile.d for files ending in '.sh'. It then sources each of them one-by-one, adding the variables set therein to your environment.

Likewise, the csh/tcsh shells run /etc/csh.login which looks into the same /etc/profile.d directory for files ending in '.csh' and does the same sourcing of them.

Try running:

$ fgrep JAVA_HOME /etc/profile.d/*.sh

and you will probably find the culprit. You can sudo-edit that file and set the proper value there, although that would be a global change for everyone logging onto the system, so consider carefully before doing that.

The purpose of those files is to allow separate packages to add environment settings germane to the user environment without having to edit the global /etc/profile file. Packages usually emplace files there in pairs of .sh and .csh with usually identical functional content.

share|improve this answer

You must log in to answer this question.

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