Last active
April 18, 2022 18:17
-
-
Save caffeinetiger/f46a62eb475a0f0c5dd4237c8e43a6ab to your computer and use it in GitHub Desktop.
[Original blog post - Switching Java (JDK) Versions on MacOS](https://medium.com/@devkosal/switching-java-jdk-versions-on-macos-80bc868e686a)
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
| #!/bin/bash | |
| # List installed JDK versions | |
| /usr/libexec/java_home -V | |
| # Export in current session | |
| export JAVA_HOME=`/usr/libexec/java_home -v <version>` | |
| # Create a function in .bashrc, .zshrc, .zshenv, etc | |
| function switch_openjdk_version() { | |
| VERSION=$1 | |
| export JAVA_HOME=`/usr/libexec/java_home -v $VERSION` | |
| } | |
| # Check java version | |
| java -version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment