Skip to content

Instantly share code, notes, and snippets.

@timyates
Last active December 22, 2015 10:49
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timyates/6461688 to your computer and use it in GitHub Desktop.
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)
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
@kousen
Copy link

kousen commented May 8, 2014

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment