Skip to content

Instantly share code, notes, and snippets.

@lstroud
Created April 15, 2014 18:08
Show Gist options
  • Save lstroud/10754107 to your computer and use it in GitHub Desktop.
Save lstroud/10754107 to your computer and use it in GitHub Desktop.
Functions to switch JVM (Java) versions on OSX
#functions placed in /etc/zshenv
alias java_ls='/usr/libexec/java_home -V 2>&1 | grep -E "\d.\d.(\d_\d\d|\d)" | cut -d , -f 1 | colrm 1 4 | grep -v Home'
alias java_home='/usr/libexec/java_home'
function java_use() {
removeFromPath $(/usr/libexec/java_home)/bin
export JAVA_HOME=$(/usr/libexec/java_home -v $1)
export PATH=$JAVA_HOME/bin:$PATH
java -version
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
#Usage
#java_ls
#java_use 1.7
#java_use 1.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment