Skip to content

Instantly share code, notes, and snippets.

@jvasallo
Created February 12, 2019 18:39
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 jvasallo/28bb1c270e0034f3cd2673b201e51d30 to your computer and use it in GitHub Desktop.
Save jvasallo/28bb1c270e0034f3cd2673b201e51d30 to your computer and use it in GitHub Desktop.
.bash_profile
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $@`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
@jvasallo
Copy link
Author

jvasallo commented Feb 14, 2019

Add this to your .bash_profile
Source it ( . .bash_profile)
setjdk 1.8
java -version
setjdk 11
java -version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment