Skip to content

Instantly share code, notes, and snippets.

@kbristow
Created March 19, 2019 12:20
Show Gist options
  • Select an option

  • Save kbristow/1d06c6097b10044c7f9f2c123c4ad2bf to your computer and use it in GitHub Desktop.

Select an option

Save kbristow/1d06c6097b10044c7f9f2c123c4ad2bf to your computer and use it in GitHub Desktop.
Set JDK version function for .bashrc
# Sourced directly from https://zeroturnaround.com/rebellabs/switching-java-versions-on-the-command-line/. Credit to Oleg Shelajev
removeFromPath () {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
# set and change 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment