Search code examples
macosbashzsh

Java_HOME not found when changed shell from Bash to Zsh on OSX?


This is weird, I have set JAVA_HOME for my mac which can be found when I am using bash shell, but if I change shell, I get a message saying JAVA_HOME not set. What could be going on here?


Solution

  • When you set JAVA_HOME in a shell, then it is active and available only for that context, and it will be gone when you close that shell.

    Instead either change global environment (or) your .bashrc to include it. So that every time you start a shell, the variable will be available.

    edit the .profile or .bash_profile to include the JAVA_HOME.

    export JAVA_HOME=`/usr/lib....`
    

    and also below command will return the path for java home directory.

    /usr/libexec/java_home -v 1.7
    

    where 1.7 is the version you want.