Created
April 15, 2014 18:08
-
-
Save lstroud/10754107 to your computer and use it in GitHub Desktop.
Functions to switch JVM (Java) versions on OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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