I try run some jar file on my user laptop and found that terminal java version is different with mac OS version. Downloading JRE is not helping because it’s not set environment variable $JAVA_HOME

This instruction may help to set $JAVA_HOME without downloading JDK.

  1. Go to System Preference > Java
  2. Check or update your java version on Update tab
  3. On Java tab, click button View to see java installation location.

    java update location

  4. Copy the path and remove bin/java
    /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    
  5. Setup environment variable on your mac
    $ echo "export JAVA_HOME=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home" >> ~/.bash_profile
    $ source .bash_profile
    
  6. Check your java version
    $ java -version