Question

I'm trying to find the location where JAVA_HOME env variale is set up and I tried to find in ~/.bash_profile , ~/.bashrc and /etc/profile but could not find the env variable.

But when I run echo $JAVA_HOME its gives out the value /usr/local/java.

Where else would the JAVA_HOME env variable.

BTW its a Red Hat Linux Server.

Was it helpful?

Solution

Try the file /etc/bash.bashrc, sometimes it is also used to initialise bash. If not, then try to find the word JAVA_HOME inside the files in /etc with grep -r BASH_HOME /etc

UPDATE

From man bash:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

and also:

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist.

So the only file that you haven't had a look at is ~/bash_login.

Probably JAVA_HOME is not in any of these files and what happens is that one of these files call another script, in that case, you'll have to read line by line if one of these scripts is "loading" more scripts from other places

OTHER TIPS

What about:

grep JAVA_HOME /etc/*

and:

grep JAVA_HOME ~/.*

Please also check variables been sourced in all startup scripts in /etc/ and also under home directory,

it will look like . path/filename or source path/filename

EX: . /etc/var or source /etc/var

There are few standard locations which environment variables can be set.

  • /etc/profile
  • shell scripts under /etc/profile.d
  • /etc/bashrc
  • ~/.bashrc
  • ~/.bash_profile

Recommended way is to put environment variables in a script under /etc/profile.d. You can grep this directory, if other locations failed.

grep -R "JAVA_HOME" /etc/profile.d/

This post can give more details on the topic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top