Skip to content

Instantly share code, notes, and snippets.

@donchesworth
Last active February 28, 2020 12:01
Show Gist options
  • Save donchesworth/a1cb2847195a43897c4b to your computer and use it in GitHub Desktop.
Save donchesworth/a1cb2847195a43897c4b to your computer and use it in GitHub Desktop.
switch between java versions
# from Johan Haleby
# added by DOC to toggle java versions
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $@`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
# type in bash: "setjdk 1.6" or "setjdk 1.8.0_66"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment