Skip to content

Instantly share code, notes, and snippets.

@rahulsom
Created December 11, 2012 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulsom/4260536 to your computer and use it in GitHub Desktop.
Save rahulsom/4260536 to your computer and use it in GitHub Desktop.
Switching JVMs in Mountain Lion

Switching JVMs in Mountain Lion

Apple made it incredibly difficult to switch JVMs since Mountain Lion. This might make it slightly easier.

Installation

  1. Download jvm.sh to ~/bin

  2. Create an alias for jvm.sh to jvm in ~/.profile or ~/.zshrc or whatever

    alias jvm="source ~/bin/jvm.sh"
  3. Start a new shell.

Usage

  1. To see current JVM and list JVMs

    jvm
  2. To unset JVM

    jvm -u
  3. To switch JVM

    jvm /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
#!/bin/bash
listJavaHomes() {
echo "Choose from:" >&2
find /Library/Java -name "Home" -type d | grep -i java
find /System/Library/Java/JavaVirtualMachines -name "Home" -type d | grep -i java
}
echo "Before: JAVA_HOME=${JAVA_HOME}" >&2
if [ "$1" = "" ]; then
listJavaHomes
elif [ "$1" = "-u" ]; then
unset JAVA_HOME
else
export JAVA_HOME=$1
fi
echo "After : JAVA_HOME=${JAVA_HOME}" >&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment