I am using Amazon corretto JDK and earlier had only 1.8 installed in my Mac OS, yesterday I installed Amazon corretto JDK 11 using the Mac OS package installer and after that it
Try adding this to your .bash_profile or .zshrc or .bashrc whatever is relevant to your macOS.
jdk() { version=$1 export JAVA_HOME=$(/usr/libexec/java_home -v"$version"); java -version }
Then, restart terminal and you can switch java versions like: