1Step-1: open terminal and type ls -al
2if you did not find the .bash_profile proceed with Step-2 else continue with Step-3
3Step-2: touch .bash_profile
4Step-3: open -e .bash_profile
5Step-4: export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
6Step-5: save it and close it
7Step-6: source ~/.bash_profile
8Step-7: echo $JAVA_HOME
11. Open terminal window
22. Type command: $ vim ~/.bash_profile and Hit Enter
33. Type command: $ export JAVA_HOME=$(/usr/libexec/java_home) and press Escape key for Save changes.
44. Type command: :(colon)wq, It will Save and close .bash_profile file.
55. Type command: source ~/.bash_profile and hit Enter
66. Now we can check the value of the JAVA_HOME variable:
77. Type Command: echo $JAVA_HOME
8 The result should be the path to the JDK installation:
9 /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home