/usr/libexec/java_home is completely broken on Big Sur

Is /usr/libexec/java_home working on Big Sur for anyone?
It won't output anything unless the JAVA_HOME environment variable is already set. When querying for the home folder for a specific version of the JDK, it always just returns the current value of the JAVA_HOME environment variable. Since the only useful purpose of the java_home tool is to get a value for setting JAVA_HOME, this is somewhat backwards and useless.

I reported this against Big Sur betas but that didn't get anywhere. In one case I was actually told it was working as designed, which is clearly not the case.

Replies

I Faced the similar issue, Javajome previously set on Catalina OS wasn't working anymore when I upgraded to Big Sur.
though the below commands worked for me
 /usr/libexec/java_home -V

/usr/libexec/java_home -v "1.8.0_241" 

export JAVA_HOME=$(/usr/libexec/java_home -v "1.8.0_241")

 echo $JAVA_HOME
I recently upgraded to Big Sur and the Java home problem started, after trying many solutions as suggested, I found a simple solution if you are using only 1 version of Java JDK

Code Block
sudo vi /etc/zprofile

press Shift + i
Add the below lines in either of the ways at the end of the zprofile file.
Code Block
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home"

OR
Code Block
export JAVA_HOME=$(/usr/libexec/java_home -v "1.8")