Skip to content

Instantly share code, notes, and snippets.

@cworks
Created April 24, 2015 03:57
Show Gist options
  • Save cworks/6022d0baf5f45121fab1 to your computer and use it in GitHub Desktop.
Save cworks/6022d0baf5f45121fab1 to your computer and use it in GitHub Desktop.
switchjava
#!/bin/zsh
function switchJava() {
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
echo "Using JAVA_HOME: ${JAVA_HOME}"
echo `java -version`
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
switchJava 1.$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment