Java 1.8 Setup for R and R Studio

Why is this so hard! There are a lot of posts out there all trying to help people get java packages working with R Studio and R on MacOSX (El Capitan, 10.11.5 in my case). I also have Java 8 installed and would prefer to use that.

This post, seemed to help me understand best what the issues were but alas, didn’t get me running the packages I wanted: FSelector which depends on RWeka and rJava. The R config file, /Library/Frameworks/R.framework/Versions/3.3/Resources/etc/Renvironis an important key, but setting variables there did not help in the way that post suggested. Here is what I did.

With a clean Renviron file, and both jdk 1.6 (RStudio seems to require this to do anything with java) from apple, and jdk1.8 from Oracle installed, jdk 8 as the default, I ran

sudo R CMD javareconf

if successful you will see a compiled program success in the output. Unfortunately you aren’t done yet. Start R and use

install.packages(‘rJava’, type=’source)

It was downloaded, compiled and ran a test compilation for me, and this worked for me but there are a couple of steps needed before a full package can actually be executed. First I needed to install X, from This will install X libraries under /opt/X11 that java looks for at run time. If you were having problems running the test program in the previous step, this may solve it for you.

Finally, you do need to link the jvm shared dylib into a place the R can find it.

ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr//locallib

and finally, we actually do need to edit the Renviron file mentioned earlier to tell the dyn loader where to find the library. Edit the end of the file so it looks like this (/Library/Frameworks/R.framework/Versions/3.3/Resources/etc/Renviron):

Local Variables: ***
### mode: sh ***
### sh-indentation: 2 ***
### End: ***
## CRAN R ships with qpdf inside so use it unless directed otherwise

After that I was able to open R Studio and load and start FSelector



gains <- information.gain(someform~., somedata.table)

I hope this helps somebody!


Comments are closed.