0

I have both java 14 and 8 installed on my laptop but want to use 8 by default so I'm trying to set my JAVA_HOME to use -v 1.8.

In ~/.bash_profile I added the line export JAVA_HOME=$(/usr/libexec/java_home -v 1.8). Immediately after doing this echo $JAVA_HOME returns the correct path and java -version returns the correct version. However, if I close terminal and open it again, echo $JAVA_HOME results in a blank line and java -version shows java 14. After editing .bash_profile I did do source ~/.bash_profile and when I reopen the terminal and do nano ~/.bash_profile the line setting JAVA_HOME is still there. Why can't I permanently set it?

mehekj
  • 1
  • Does this answer your question? [How to set JAVA\_HOME in Mac permanently?](https://stackoverflow.com/questions/14702702/how-to-set-java-home-in-mac-permanently) – andreoss Jun 24 '20 at 00:23
  • 1
    Could be that `.bash_profile` is not being executed automatically. Mac's default shell isn't bash any more. You could try putting it in `.profile` instead. – khelwood Jun 24 '20 at 00:26
  • Is your terminal set up to use a login shell? If not, it won't source bash_profile by default. Terminal settings => General => "Shells open with" – glenn jackman Jun 24 '20 at 00:36
  • @khelwood I did try this but still the same result. It works at first but if I close terminal and reopen, echo $JAVA_HOME is blank again and java -version is 14 again. – mehekj Jun 24 '20 at 00:38
  • @glennjackman Mine is set to open with default login shell – mehekj Jun 24 '20 at 00:40

1 Answers1

0

Managed to answer my own question. My terminal is using zsh not bash so I just had to set it in .zshenv not .bash_profile

mehekj
  • 1