Question: I am having an issue trying to upgrade to Java 8 from Java 6 on my Mac running Mac OS X 10.10.5, with Java 8 seemingly not getting recognized.

I installed Java 8 via the .dmg installer: jre-8u66-macosx-x64.dmg, yet when I enter: java -version, it reports:
java version "1.6.0\_65".

Yet, I noticed under the Java Panel via System Preference, the Java Runtime Environment Settings Panel is displaying 1.8.0\_102.

From poking around I have noticed:
1) Java 8 seems to have installed into: /Library/Java/JavaVirtualMachines/jdk1.8.0\_102.jdk

2) Java 6 seems to have been installed into:
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk

I then noticed a post on StackOverflow recommending to use "brew" to install Java, and not use the official installer for Mac, as it is broken. When I went to install brew I got this error message:

/usr/bin/ruby -e "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/master/install>)"

I got this error message: Illegal variable name.
And then I read that "brew" is broken on versions of El Capitan and above.

So, what do I need to do to get this upgrade to Java 8 to work???
Appreciate any help with this! Thanks!

Answer: 
your java command points to the stub binary which uses current version configured

```
$ ls -la /usr/bin/java
lrwxr-xr-x  1 root  wheel  74 Feb  5  2015 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

```

all you need is to update your `JAVA_HOME`(I've added that to my `~/.profile`):

```
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

```

There's a topic which describes this in-depth [Need help understanding Oracle's Java on Mac](https://stackoverflow.com/questions/15120745/need-help-understanding-oracles-java-on-mac)
I don't know about the brew thing. Looks like you have two jdks and the one with /System/Library/Java/JavaVirtualMachines/1.6.0.jdk has the $PATH set for it but the new one you installed doesn't have its $PATH set for it yet. I would recommend following, 
i. either delete the old one and then set the $PATH for new one
ii. just set the $PATH for new one but try to keep both JDK in same location
in both cases you want to have $JAVA\_HOME yield the path for your latest jdk which should work. 
here is link that might be helpful 
<https://cloudlink.soasta.com/t5/CloudTest-Knowledge-Base/Adding-JDK-Path-in-Mac-OS-X-Linux-or-Windows/ta-p/43867>
for setting the $PATH for you. In plain terms, you have to find a file in your mac that is called .bash\_profile and then in that file you have to set the $PATH for your new jdk or which ever jdk you want to work with. This should take little research if you don't know but its not very difficult. Hope this helps..