Specify jdk version on bash
This is an example to specify jdk 1.8 on bash script.
This is an example to specify jdk 1.8 on bash script.set -eexport JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
export PATH=$JAVA_HOME/bin:$PATH
Before use this command, we need install jdk 1.8 on local machine, and install multiple versions.
In my environment, I installed multiple jdk versions, such as jdk 1.8, 11, 15, 16, 17. But one command needs jdk 1.8, and my default version is jdk 11, in order use the jdk 8 for the command, the above setting works for me.