Download Open JDK on https://jdk.java.net/. Example jdk version is using 17, then extarct jdk archive, and move to directory where you want, recommended jdk location move at /Library/Java/JavaVirtualMachines/
.
Edit file .bashrc
or .profile
or .zshrc
at your home place, and register bin
jdk on path, add this code at bottom:
export PATH="/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home/bin:$PATH"
check the list of installed JDK
/usr/libexec/java_home -V
# output
Matching Java Virtual Machines (1):
17.0.2, x86_64: "OpenJDK 17.0.2" /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home