title: How should I set the JAVA_HOME environment variable on macOS?
body: <p>I know this question has been asked a lot before but i did read and i will show you what i got.</p>
  
  <p>I will list the commands that i did in my <strong>OS X Yosemite 10.10.1</strong></p>
  
  <p><strong>java -version</strong></p>
  
  <pre><code>java version "1.8.0_45"
  Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
  Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
  </code></pre>
  
  <p><strong>java -fullversion</strong></p>
  
  <pre><code> java full version "1.8.0_45-b14"
  </code></pre>
  
  <p><strong>which java</strong></p>
  
  <pre><code>/usr/bin/java
  </code></pre>
  
  <p>Java home variable is not set because when I do this: <strong>echo $java_home</strong> or <strong>echo $JAVA_HOME</strong> or <strong>echo $Java_Home</strong> i got nothing on the terminal.</p>
  
  <p>when doing this: ls -l <code>which java</code>  i got this:</p>
  
  <pre><code>8 lrwxr-xr-x  1 root  wheel  74 Nov 12  2014 /usr/bin/java -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
  </code></pre>
  
  <p><strong>javac -version</strong></p>
  
  <pre><code>javac 1.8.0_45
  </code></pre>
  
  <p><strong>/usr/libexec/java_home</strong></p>
  
  <pre><code>/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
  </code></pre>
  
  <h3>The solution that I think is correct after reading on internet is </h3>
  
  <pre><code>echo "export JAVA_HOME=`/usr/libexec/java_home`" &gt;&gt; ~/.profile  
  </code></pre>
  
  <p>but i am afraid to test it, that is why i am asking you, if that is correct or not and if not what should i do please?</p>