title: How to set the Java path installed by Homebrew?
body: <p>Java 9 is installed in my MacBook (OS X 10.11 El Capitan). As I needed Java 8, I've installed it using Homebrew.</p>
  
  <pre><code>$ brew cask install java8
  </code></pre>
  
  <p>However, the Java version is still 9 in the terminal.</p>
  
  <pre><code>$ java -version
  java version "9"
  Java(TM) SE Runtime Environment (build 9+181)
  Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode) 
  </code></pre>
  
  <p>The install location of the current Java seems to be in <code>/System/Library/Frameworks/.../Commands</code></p>
  
  <pre><code>$ ls -la /usr/bin/java
  lrwxr-xr-x  1 root  wheel  74 Sep 23  2017 /usr/bin/java -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
  </code></pre>
  
  <p>Homebrew seems to have installed Java 8 in </p>
  
  <pre><code>/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/
  </code></pre>
  
  <p>Of course I could just prepend the above path to the <code>PATH</code> environment variable in <code>~/.profile</code>, but I wanted to know whether there is a more robust way of setting the path for the older Java version.</p>