Search code examples
javajava-8java-home

JAVA_HOME set wrongly


When I do echo $JAVA_HOME , I get /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

But When I do /usr/libexec/java_home, I get /Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home

I think both of them should return /Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home but $JAVA_HOME doesn't return that.

I put export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) in .bash_profile. What's my issue? how to change JAVA_HOME?


Solution

  • I can see a couple of problems with your setup and commands. Execute the following commands:

    $ cd ~
    $ vi .bash_profile 
    

    Put the following line in this file:

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

    Save and exit the file and then execute the following commands:

    $ source .bash_profile
    $ echo $JAVA_HOME
    

    Now, you should be able to get the results correctly.

    Regarding setting Java-8:

    Execute the following command:

    $ /usr/libexec/java_home -V
    

    This should print all JDK versions installed in your system. Now, copy the exact version number of Java-8 (e.g. 1.8.0_181) from the list and execute the following command:

    export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0_181)