Question: This question is related to [this other question](https://stackoverflow.com/questions/26618105/rnetlogo-not-working-on-mac-yosemite/26723881#26723881).

I am trying to use RNetLogo with R and get the following error.

```
nl.path <- "/Applications/NetLogo 5.1.0"
NLStart(nl.path) 
Error in .jnew("nlcon/Preprocess") : 
  java.lang.UnsupportedClassVersionError: nlcon/Preprocess : Unsupported major.minor version 51.0

```

From what I understood in [this other question](https://stackoverflow.com/questions/26618105/rnetlogo-not-working-on-mac-yosemite/26723881#26723881), the problem is that R is using an old version of Java which is incompatible with RNetLogo. 

I installed Java 8.0 hoping to solve the problem but my understanding is that, despite Java 8.0 being installed on my computer (Mac OS Maverick), R does not pick it up and keep trying to use old versions of Java. 

So my question is : How can I get R to use Java 8.0 instead of any older version?

In the terminal console, I get

```
java -version :
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

```

Thanks in advance for your help,

Answer: 
This supposedly works (originally from this [blog](http://conjugateprior.org/2014/12/r-java8-osx/) entry):

1) Download and install Apple’s Java version 1.6.

2) Reconfigure your Java installation by using `sudo R CMD javareconf -n`.

3) Reinstall `rJava` from source with: `install.packages('rJava', type='source')`.

Please acknowledge Will Lowe at [conjugateprior.org](http://conjugateprior.org) for the original post and solution.
In Ubuntu there is a command `alternatives` that i use it for this purpose.

```
alternatives --install /usr/bin/java java /usr/java/jdk1.8*/jre/bin/java 200000
alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.8*/jre/bin/javaws 200000
alternatives --install /usr/bin/javac javac /usr/java/jdk1.8*/bin/javac 200000
alternatives --install /usr/bin/jar jar /usr/java/jdk1.8*/bin/jar 200000

```

After alternatives install use the following command to change your version.
`alternatives --config java` and then select your newer java.

If this is not available you should first find out what where is your new java actually.
`locate *jdk1.8*`
Then find out which java you run as binary. `which java` this will returns the path of binary. this is the old java binary, So remove it and link new java binary in the same place. For example : `ln -s /path/to/java1.8*/bin/java /usr/bin/java` 

In addtion you need to update your CLASS\_PATH environment variable that is necessary for the VM.

for example:
`export CLASS_PATH=/usr/java/jdk1.8*/jre/lib` and you can add this line in your `bashrc` file to register this configuration.