conjugateprior

Getting R and Java 1.8 to work together on OSX


Hey Mac OSX users with Java 1.8 installed. Did R just request a Java 1.6 installation and then promptly crash your session? If so, read on…

The Problem

A few days ago I was attempting to use the mallet package for topic models and I found that typing

library(mallet)

caused two things to happen:

  1. The operating system launches a dialog asking whether I would like to download Java 1.6

  2. The R session crashes (regardless of what I did about the dialog)

This seems to be a general problem for packages that depends on the rJava package.

I’m running the latest Mac OSX (Yosemite 10.10.1) and have installed the latest Java

$ java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

and the latest R

$ R --version
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

But for some reason with R, it’s Java 1.6 (which is no longer even being updated) or bust.

The fix (maybe)

The trail of bug reports starts here, but before you delve into those and bother Simon Urbanek as much as I did, try the following:

  1. Download and install Apple’s Java version 1.6 like you were asked to.

  2. Reconfigure your R installation by typing

    sudo R CMD javareconf
    

    in a Terminal window. (Thanks to commenter Benjamin for pointing out that there shouldn’t have been a -n flag in this line)

  3. Trigger a recompile by reinstalling rJava by typing

    install.packages('rJava', type = 'source')
    

Now if you relauch R and load your package it should use your shiny new Java 1.8 and not crash any R sessions.

Late addition

For this to work you may have to set (or have something else set) some environment variables too. See the comments below for my settings.

Addendum 2020

Just give up. Six years later it still seldom works. I now find it quicker and much less exasperating to write out shell commands to run the Java code with system2. Heck it’s probably more efficient to rewrite the Java in C++ and call it with Rcpp.

Archived comments

From the Internet Archive


If you found this helpful...

ko-fi page

License

This page has an open-source license (Creative Commons BY-NC-ND)

Creative Commons License BY-NC-ND