1

I am using Mac, and $JAVA_HOME environment path is set in ~/.bash_profile like:

export JAVA_HOME=$(/usr/libexec/java_home)

After I updated Java, bash kept trying to find Java from the older version.

I had to run source ~/.bash_profile to tell bash the new Java path every time I open a new terminal. Is there any configuration overrides my setting in .bash_profile?

1

A change made to ~/.bash_profile will only be seen in new shell sessions (new terminal windows). A new shell session will parse the updated configuration file and will have the new $JAVA_HOME value.

This assumes that the terminal starts new shells as login shells. If it doesn't, the change should go into ~/.bashrc. If you're not using bash but some other shell, the filename will depend on what shell you're using.

To change the value of $JAVA_HOME in an existing session, you will have to set the value explicitly on the command line, or, as you discovered, source the shell initialization file (which may or may not have other side effects depending on what the other commands in the file are doing).

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.