Skip to content

Instantly share code, notes, and snippets.

@kblum
Forked from dannyfallon/rubymine_jdkchange.sh
Last active November 23, 2015 12:53
Show Gist options
  • Save kblum/9b6f77b0913fbd5e8723 to your computer and use it in GitHub Desktop.
Save kblum/9b6f77b0913fbd5e8723 to your computer and use it in GitHub Desktop.
JetBrains IDE JVM Version Change.
#!/usr/bin/env bash
set -e
if [ -z "$1" ]; then
echo "Must specify app name as argument; exiting"
exit
fi
APP_NAME=`echo "$1" | tr '[:upper:]' '[:lower:]'` # convert to lowercase
case "$APP_NAME" in
intellij)
echo "Changing Java version for IntelliJ 14"
APP_PREF_DIR='IntelliJIdea14'
APP_INSTALL_DIR='IntelliJ IDEA 14.app'
;;
rubymine)
echo "Changing Java version for RubyMine 7"
APP_PREF_DIR='RubyMine70'
APP_INSTALL_DIR='RubyMine.app'
;;
pycharm)
echo "Changing Java version for PyCharm 4"
APP_PREF_DIR='PyCharm40'
APP_INSTALL_DIR='PyCharm.app'
;;
androidstudio)
echo "Changing Java version for Android Studio 1.5"
APP_PREF_DIR='AndroidStudio1.5'
APP_INSTALL_DIR='Android Studio.app'
;;
webstorm)
echo "Changing Java version for WebStorm 10"
APP_PREF_DIR='WebStorm10'
APP_INSTALL_DIR='WebStorm.app'
;;
clion)
echo "Changing Java version for CLion 1.1"
APP_PREF_DIR='clion11'
APP_INSTALL_DIR='CLion.app'
;;
*)
echo "Must specify a valid application; exiting"
exit
;;
esac
# Get the java version, quit if it's not found
JAVA_VERSION=`java -version 2>&1 | head -n 1 | cut -d\" -f 2 | cut -c1-3`
if [ -z "$JAVA_VERSION" ]; then
echo "Unable to determine Java version; exiting"
exit
fi
# Create the preferences directory
mkdir -p "$HOME/Library/Preferences/$APP_PREF_DIR"
# Copy the original idea.properties file (maintains app signing for patches/updates)
cp "/Applications/$APP_INSTALL_DIR/Contents/bin/idea.properties" "$HOME/Library/Preferences/$APP_PREF_DIR/"
# Replace the JVM version with the one we actually use
sed -i.bak "s/JVMVersion=.*/JVMVersion=$JAVA_VERSION*/g" "$HOME/Library/Preferences/$APP_PREF_DIR/idea.properties"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment