According to the error your mac uses z shell which has file .zshrc for environment variables. Begin by identifying the directory where Java is installed on your Mac. Typically, Java resides in the ‘/Library/Java/JavaVirtualMachines/’ directory. Open terminal and follow these steps -
Open .zshrc in vim editor
vim ~/.zshrc
Press Insert or i (insert mode) Paste the java path — —
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
Escape and then press :x (To save and exit)
Verify JAVA_HOME environment variable is correctly set up.
source ~/.zshrc
echo $JAVA_HOME
Restart terminal for the changes to reflect or better restart your mac.