Skip to content

Instantly share code, notes, and snippets.

@matthewadams
Last active December 18, 2015 09:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewadams/5760495 to your computer and use it in GitHub Desktop.
Save matthewadams/5760495 to your computer and use it in GitHub Desktop.
Easy JVM switcher script for Mac OS X
#!/bin/bash
if [ ! $1 ]; then
echo "Please include desired jdk version: 1.7 or 7, 1.6 or 6, ..."
exit
fi
j7="/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home"
#j6="/Library/Java/JavaVirtualMachines/1.6.0_45-b06-451.jdk/Contents/Home"
j6="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"
case $1 in
"1.7" | "7") export JAVA_HOME=$j7 ;;
"1.6" | "6") export JAVA_HOME=$j6 ;;
*)
echo "Supported versions are 1.6, 6, 1.7, or 7"
exit
;;
esac
# scrub path of any JAVA_HOMEs
for j in "$j7" "$j6"
do
PATH=`echo $PATH | sed s,"$j/bin",,g`
done
if [ "$2" == "all" ]; then
# replace for entire machine by replacing symlink
rm ~/.java
ln -s $JAVA_HOME ~/.java
else
# replace for just this shell by prepending java to scrubbed path
export PATH=$JAVA_HOME/bin:$PATH
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment