Last active
December 22, 2015 10:49
-
-
Save timyates/6461688 to your computer and use it in GitHub Desktop.
Two bash functions to switch JVM on OS X (with GVM installed as well)
This file contains hidden or 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
export JAVA7_HOME=`/usr/libexec/java_home -v 1.7*` | |
export JAVA8_HOME=`/usr/libexec/java_home -v 1.8*` | |
function jdk7 { | |
export JAVA_HOME=$JAVA7_HOME | |
set_path | |
echo "Using Java 7 $JAVA_HOME" | |
} | |
function jdk8 { | |
export JAVA_HOME=$JAVA8_HOME | |
set_path | |
echo "Using Java 8 $JAVA_HOME" | |
} | |
function set_path { | |
PATH=/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin | |
PATH=$PATH:$JAVA_HOME/bin | |
PATH=$PATH:/usr/local/mysql/bin/ | |
# Set other path vars here | |
# Reload GVM | |
export GVM_INIT= | |
[[ -s "/Users/tyates/.gvm/bin/gvm-init.sh" && ! $(which gvm-init.sh) ]] && source "/Users/tyates/.gvm/bin/gvm-init.sh" | |
} | |
jdk7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Tim. Thanks for this. Any chance you could provide a version that works on zsh as well? I'm a happy oh_my_zsh user, and your GVM_INIT implementation confuses it.
Also, I use the Oracle Java installer, so I usually have to set my path directly rather than use the java_home command, unless I'm doing something wrong (likely).