5 followers Follow

rJava fails to load in RStudio Desktop OS X

I am having the dreaded "Error : .onLoad failed in loadNamespace() for 'rJava'" error when trying to load rJava in RStudio. I have read the other rJava issues and tried lots of different solutions, but none solves the issue for me.

I am running RStudio Desktop for OS X (0.98.159) and R 3.0.1 (installed via homebrew). rJava (0.9-5) loads fine in R run from the terminal, so I think javareconf set up everything correctly. Since most of the solutions involved LD_LIBRARY_PATH, I've been trying those.

Launching R from the terminal gives me LD_LIBRARY_PATH of


which is slightly different from what launching from the dock gives:


differing by only :@JAVA_LD@.

So far I have tried (all with the same error above):

  1. Within RStudio setting LD_LIBRARY_PATH to the same value as terminal R:

    Sys.setenv(LD_LIBRARY_PATH = "/usr/local/Cellar/r/3.0.0/R.framework/Resources/lib:/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/jre/lib/server:@JAVA_LD@")

  2. From the terminal: open -a rstudio
    LD_LIBRARY_PATH is ":@JAVA_LD@", but I still have the error.

  3. Set LD_LIBRARY_PATH to the same as above in my .Renviron.

Is there anything else I can try?


Ian Pylvainen



Not sure if it's the same problem, but I ran into a similar issue with RStudio and rJava once I installed Java 1.7 on my mac (OSX 10.7). First I followed the following SO instructions to get rJava to bind to Java 1.7 rather than 1.6:

That fixes rJava in the R console, but when running RStudio I got a similar error to the one mentioned above. Tried both the latest release (v0.97.551) as well as the latest daily build (v0.98.202) but no luck. I also saw a difference in the LD library path between the R console and RStudio. In R I got:

system("env | grep LD")
whereas with RStudio I got
system("env | grep LD")

The hack that ended up working for me was to run RStudio from the terminal with the LD_LIBRARY_PATH set explicitly, via the following command:
LD_LIBRARY_PATH=/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/server: open -a rstudio

Based on earlier discussions in this forum I thought this problem was resolved, but it seems to have resurfaced, hopefully it'll get resolved in a future version. For now, this hack seems to work, at least in my case.

Ian Pylvainen 0 votes

+1 here.

Happy to support the RStudio team if you need anything. I am using RStudio 0.98.472 and R 0.3.2 on MacOS 10.8.5. The error I am getting - in RStudio only - is:

> library(rJava)
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/usr/local/Cellar/r/3.0.2/R.framework/Versions/3.0/Resources/library/rJava/libs/': dlopen(/usr/local/Cellar/r/3.0.2/R.framework/Versions/3.0/Resources/library/rJava/libs/, 6): Library not loaded: @rpath/libjvm.dylib
  Referenced from: /usr/local/Cellar/r/3.0.2/R.framework/Versions/3.0/Resources/library/rJava/libs/
  Reason: image not found
Error: package or namespace load failed for ‘rJava’

The MacOS' Java version is:

$ java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)


Ian Pylvainen 0 votes

The problem re-surfaced again.

My system:
OS X: 10.9
R: 3.1.1 (installed with Homebrew)
Java: Oracle JDK 1.7.0_51
RStudio: 0.98.1028

The hack is still effective.

Michael Chen 0 votes

This work around is not working for me.

library(rJava) works on command line R but not in RStudio.

My system:
OS X: 10.10
R: 3.1.0
Java: Oracle JDK 1.7.0_71
RStudio: 0.98.1091

Cary Bourgeois 1 vote

The problem seemed to be solved when I revert my system to the default Java install on Mac OS X.

Simon Garnier 0 votes