Created
June 1, 2022 14:49
-
-
Save danslapman/42a16c50d1a29b03c2f100c9507fe675 to your computer and use it in GitHub Desktop.
JDK switcher for MacOS
This file contains hidden or 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
export JAVA_HOME=$(/usr/libexec/java_home -v 17) | |
jdk() { | |
version=$1 | |
escaped=$(echo $JAVA_HOME | sed -e 's/[]\/$*.^[]/\\&/g') | |
pattern=$(printf 's/%s\/bin://g' "$escaped") | |
export PATH=$(echo $PATH | sed -e "$pattern") | |
export JAVA_HOME=$(/usr/libexec/java_home -v "$version") | |
export PATH=$JAVA_HOME/bin:$PATH | |
java -version | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment