Wednesday, May 03, 2023

Java JDK on Mac

 These are my notes on how I setup a Java JDK on my mac.

Currently I have several JDK's installed.
To see the installations go to:
/usr/libexec

Run:
./java_home -V
Matching Java Virtual Machines (5):
    17.0.1 (x86_64) "Homebrew" - "OpenJDK 17.0.1" /usr/local/Cellar/openjdk/17.0.1/libexec/openjdk.jdk/Contents/Home
    17.0.1 (x86_64) "Amazon.com Inc." - "Amazon Corretto 17" /Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home
    11.0.19 (x86_64) "Amazon.com Inc." - "Amazon Corretto 11" /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
    1.8.0_322 (x86_64) "Amazon" - "Amazon Corretto 8" /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home

I use a symbolic link in /usr/local/opt to point to the java I want to use.
I make the symbolic link as follows:

ln -sfn /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home currentjdk
Now the symbolic link "currentjdk" points to the JDK that I want.
Next I edit /etc/profile

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
        eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
        [ -r /etc/bashrc ] && . /etc/bashrc
fi


export JAVA_HOME="/usr/local/opt/currentjdk"

export PATH=$JAVA_HOME/bin:$PATH

After you edit the profile you can create a new terminal and see the current version of java:

$java -version
openjdk version "11.0.19" 2023-04-18 LTS
OpenJDK Runtime Environment Corretto-11.0.19.7.1 (build 11.0.19+7-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.19.7.1 (build 11.0.19+7-LTS, mixed mode)

No comments: