First, Check if there are any version of java installed. I just bought a 2013 iMac on Ebay, and set it up tabula rosa.
iMac:~ $ /usr/libexec/java_home -V
Unable to find any JVMs matching version "(null)".
Matching Java Virtual Machines (0):
Default Java Virtual Machines (0):
No Java runtime present, try --request to install.
Mac OS looks for java in the /Library/Java/JavaVirtualMachines/ directory. Therefore if we download a valid Java JDK, and "copy" the un-archived structure over to that directory, we will see that it works. This is done as follows.
Java 13 is available from Java 13 link - > https://jdk.java.net/13/ or it can obtained via wget with:
iMac:java $ wget https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_osx-x64_bin.tar.gz
--2020-02-04 19:01:16-- https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_osx-x64_bin.tar.gz
Resolving download.java.net (download.java.net)... 104.87.12.11
Connecting to download.java.net (download.java.net)|104.87.12.11|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 189969691 (181M) [application/x-gzip]
Saving to: ‘openjdk-13.0.2_osx-x64_bin.tar.gz’
openjdk-13.0.2_osx-x64_bin.tar.gz 7%[====> ] 13.50M 254KB/s eta 9m 8s
Once this has been downloaded: it can be extracted and copied or move to the /Library/Java/JavaVirtualMachines/ directory.
Extract with the "tar -xvzf openjdk-13.0.2_osx-x64_bin.tar.gz" which says eXtract Verbose Compressed(z) Filesystem.
$ tar -xvzf openjdk-13.0.2_osx-x64_bin.tar.gz
$ mv jdk-13.0.1.jdk/ /Library/Java/JavaVirtualMachines/
Re-running the /usr/libexec/java_home -V command gives:
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
13.0.1, x86_64: "OpenJDK 13.0.1" /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
And 'java -version' on the command line gives:
$ java -version
openjdk version "13.0.1" 2019-10-15
OpenJDK Runtime Environment (build 13.0.1+9)
OpenJDK 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)
After downloading and installing several different version of java (which included creating an oracle account, and getting one of the "legacy/archived" version of java from the oracle website) my lib execute for java home looked like this:
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (4):
13.0.1, x86_64: "OpenJDK 13.0.1" /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
11.0.6, x86_64: "Java SE 11.0.6" /Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home
1.8.0_241, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home
1.7.0_80, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
PLACE THIS IN YOUR ~/.bash_profile or other startup environment script directory
export JAVA_HOME_7=$(/usr/libexec/java_home -v1.7)
export JAVA_HOME_8=$(/usr/libexec/java_home -v1.8)
#export JAVA_HOME_9=$(/usr/libexec/java_home -v9)
#export JAVA_HOME_10=$(/usr/libexec/java_home -v10)
export JAVA_HOME_11=$(/usr/libexec/java_home -v11)
export JAVA_HOME_13=$(/usr/libexec/java_home -v13)
alias java7='export JAVA_HOME=$JAVA_HOME_7'
alias java8='export JAVA_HOME=$JAVA_HOME_8'
#alias java9='export JAVA_HOME=$JAVA_HOME_9'
#alias java10='export JAVA_HOME=$JAVA_HOME_10'
alias java11='export JAVA_HOME=$JAVA_HOME_11'
#alias java12='export JAVA_HOME=$JAVA_HOME_12'
alias java13='export JAVA_HOME=$JAVA_HOME_13'
#default
java13
$ source ~/.bash_profile
Now switching from java13 to java7 is as easy as typing $ java7 at the command line E.G.
iMac:~ $ java7
iMac:~ $ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
iMac:~ $ java8
iMac:~ $ java -version
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
iMac:~ $ java11
iMac:~ $ java -version
java version "11.0.6" 2020-01-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.6+8-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.6+8-LTS, mixed mode)
iMac:~ $ java13
iMac:~ $ java -version
openjdk version "13.0.1" 2019-10-15
OpenJDK Runtime Environment (build 13.0.1+9)
OpenJDK 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)