Download the Java SDK from Oracle
Check reference links below.
Switch Between Multiple Java Versions
Run command in shell
/usr/libexec/java_home -V
An example of the output
Matching Java Virtual Machines (2):
12.0.1, x86_64: "Java SE 12.0.1" /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home
1.8.0_212, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home
Switching to 1.8.0_212
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_212`
Or Switching to 12.0.1
export JAVA_HOME=`/usr/libexec/java_home -v 12.0.1`
Check the version
java -version
Reference
- Java 8 Downloads URL
- Java 8 Checksum
- https://stackoverflow.com/questions/21964709/how-to-set-or-change-the-default-java-jdk-version-on-os-x