Created
August 14, 2019 01:35
-
-
Save ansell/a634e34b0099a4a831d9e64d6fbcb2b2 to your computer and use it in GitHub Desktop.
HomeBrew Revert to Java8 from Java9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# Uninstall Java 9 off the bat, so we can fix our local installation | |
if brew cask ls --versions "java" &>/dev/null; then | |
echo "Uninstalling Java" | |
brew cask uninstall java | |
fi | |
# Install jenv, java8 and java9 | |
brew install jenv | |
brew cask install caskroom/versions/java8 | |
brew cask install java | |
# Remove orphans or bad previous installs so we manage things from a clean state | |
old_versions="$(jenv versions --bare)" | |
for java_version in ${old_versions}; do | |
if [ "${java_version}" == "system" ]; then | |
continue | |
fi | |
echo "Un-managing: ${java_version}" | |
jenv remove "${java_version}" | |
done | |
# Manage all currently installed versions | |
for path in /Library/Java/JavaVirtualMachines/*; do | |
full_path="${path}/Contents/Home" | |
echo "Now managing: ${full_path}" | |
jenv add "${full_path}" | |
done | |
# Set default to Java 8 | |
jenv global 1.8 | |
jenv rehash | |
# Get maven and gradle to play nice (you might have to run these two commands manually) | |
jenv enable-plugin maven | |
jenv enable-plugin gradle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An alternative to
jenv enable-plugin maven
is to add the following to~/.mavenrc