Skip to content

Java ‐ Install JDKs

Federico Failla edited this page May 24, 2024 · 5 revisions

Install JDKs

Our Java services currently run on either Java 8 or Java 11.

# Homebrew (Mac OS)

Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

brew tap homebrew/cask-versions

Install JDK 1.8

brew install openjdk@8

sudo ln -sfn /usr/local/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk

Install JDK 11

brew install openjdk@11

sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk

List installed Java versions

/usr/libexec/java_home -V

Switch Between JDK Versions

Since different services run on different JRE’s, switching between JDK versions is necessary when running the build commands from the command line.

  1. Add the following to ~/.zshrc (or ~/.bashrc if using bash)

     jdk() {
    
       version=unset JAVA_HOME;
    
       export JAVA_HOME=$(/usr/libexec/java_home -v"$version");
    
       java -version
    
     }
    
  2. Source to reflect changes

source ~/.zshrc

Switch between JDK versions

% jdk 1.8

openjdk version "1.8.0_312"

OpenJDK Runtime Environment (build 1.8.0_312-bre_2021_10_20_23_15-b00)

OpenJDK 64-Bit Server VM (build 25.312-b00, mixed mode)

% jdk 11

openjdk version "11.0.12" 2021-07-20

OpenJDK Runtime Environment Homebrew (build 11.0.12+0)

OpenJDK 64-Bit Server VM Homebrew (build 11.0.12+0, mixed mode)

Show current Java version

java -version