You can set JAVA_HOME in Mac OS X 10,10 or Yosemite by adding the following command in your ~/.bash_profile file, as shown below:
This will append export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" into your bash_profile file. If you have set JAVA_HOME in UNIX then it's exactly similar to that.
export JAVA_HOME=`/usr/libexec/java_home` (remember backticks)or
echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" >> ~/.bash_profile
This will append export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" into your bash_profile file. If you have set JAVA_HOME in UNIX then it's exactly similar to that.