Skip to content

Instantly share code, notes, and snippets.

@ruudud
Last active December 19, 2015 04:39
Show Gist options
  • Save ruudud/5899133 to your computer and use it in GitHub Desktop.
Save ruudud/5899133 to your computer and use it in GitHub Desktop.
Script to change Java JDK in OSX. Only tested on Mountain Lion, other versions should use the Java Preferences app.
#!/bin/bash
TXTBLD=$(tput bold)
TXTRST=$(tput sgr0)
JVMS="/System/Library/Java/JavaVirtualMachines"
JAVA7="jdk1.7.0_17.jdk"
JDKS="~/.jdks"
usage () {
echo "Usage: `basename $0` {6|7}" 1>&2
echo -e "\n"
echo "$TXTBOLD Warning: $TXTRST Expects JDK1.7 to be found in $JDKS/$JAVA7"
echo -e "\n"
exit 0
}
if [ $# -lt 1 ]
then
usage
fi
case "$1" in
6) echo "Setting Java to version 6…"
sudo rm -rf "$JVMS/$JAVA7"
exit $?
;;
7) echo "Setting Java to version 7…"
sudo cp -r $JDKS/$JAVA7 $JVMS
exit $?
;;
*) usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment