[java] How to set or change the default Java (JDK) version on OS X?

First find out where do you store the environment variables-

  1. emacs
  2. bash_profile
  3. zshrc file

Steps to Set up the environment variable :-

  1. Download the jdk from JAVA

  2. install it by double click

  3. Now set-up environment variables in your file

    a. For emacs.profile you can use this link OR see the screenshot below

enter image description here

b. For ZSH profile setup -

1. export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home

2. source ~/.zshrc - Restart zshrc to reflect the changes.

3. echo $JAVA_HOME - make sure path is set up properly 
   ----> /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home

4. java -version 

   -->  java version "1.8.0_112"  Java(TM) SE Runtime Environment (build 1.8.0_112-b16)Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)

All set Now you can easily upgrade or degrade the JAVA version..