Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@massenz
Last active December 12, 2019 11:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save massenz/faff155523a50313be6f25a5b631a63d to your computer and use it in GitHub Desktop.
Save massenz/faff155523a50313be6f25a5b631a63d to your computer and use it in GitHub Desktop.
Install OpenJDK 10 on MacOS
#!/bin/bash
#
# Installs the OpenJDK 10 from java.net.
VERSION=10.0.2
DOWNLOAD_URL="download.java.net/java/GA/jdk10"
JDK="openjdk-${VERSION}_osx-x64_bin.tar.gz"
INSTALL_DIR="/Library/Java/JavaVirtualMachines"
wget https://${DOWNLOAD_URL}/${VERSION}/19aef61b38124481863b1413dce1855f/13/${JDK} -O /tmp/${JDK}
sudo tar xfz /tmp/${JDK} -C ${INSTALL_DIR}
# Locating the current JDK and associated JAVA_HOME.
#
# Usage: jhome [VERSION]
# Optional VERSION argument, to locate the JAVA_HOME
# for that version of the JDK (e.g., jhome 10)
#
function jhome {
local version=${1:-}
if [[ -n ${version} ]]
then
java_home=$(/usr/libexec/java_home -v ${version})
if [[ $? == 0 ]]
then
echo ${java_home}
return 0
fi
return 1
fi
echo $(/usr/libexec/java_home)
}
# Add these to your .bash_aliases, or .zshrc
#
alias j8='export JAVA_HOME=$(jhome 1.8)'
alias j9='export JAVA_HOME=$(jhome 9)'
alias j10='export JAVA_HOME=$(jhome 10)'
# This may also be helpful to list the installed JVMs:
alias javals="/usr/libexec/java_home -V 2>&1 | grep -E "\d.\d.\d(_\d\d)?" | cut -d , -f 1 | colrm 1 4 | grep -v Home"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment