Skip to content

Instantly share code, notes, and snippets.

@gacha
Created February 17, 2020 17:51
Show Gist options
  • Save gacha/245810ea8ed4e6045829b47b1ee419d6 to your computer and use it in GitHub Desktop.
Save gacha/245810ea8ed4e6045829b47b1ee419d6 to your computer and use it in GitHub Desktop.
Simple function to switch java versions
function switch_java {
version=$1
if [[ $version -lt 10 ]]; then
version="1.$version"
fi
new_home=$(/usr/libexec/java_home -v $version 2&> /dev/null)
if [[ $new_home != $JAVA_HOME ]]; then
export JAVA_HOME=$new_home
echo "new JAVA_HOME=$JAVA_HOME"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment