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?

U880D
  • 1,146
M. Wu
  • 11
  • 2

2 Answers2

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).

Kusalananda
  • 333,661
0

Instead of

export JAVA_HOME ~ Blah

on your bash_profile or zshrc, use

export PATH = <YOUR FULL LOCATION JDK>/bin:$PATH

Now anytime it will work. You have to add bin.

Paulo Tomé
  • 3,782
aumd laqe
  • 101