Heisenberg
Heisenberg

Reputation: 8806

rJava package load error only when using RStudio (possible LD_LIBRARY_PATH issue)

I'm encountering the same error message discussed in this question, which boils down to:

Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/home/anh/Rlibs/rJava/libs/rJava.so':
  libjvm.so: cannot open shared object file: No such file or directory

The problem is that following the answer there (i.e. setting LD_LIBRARY_PATH to point to libjvm.so) solved my issue in command-line R, but Rstudio cannot find libjvm.so still.

System specs: Ubuntu 14.04, R 3.1.1, Rstudio Desktop 0.98, apt-get install r-cran-rjava done

Upvotes: 4

Views: 4546

Answers (2)

Sam
Sam

Reputation: 840

Yep. What is suggested by Heisenberg works for me, although the specfic command that I put in ~/.profile is

export LD_LIBRARY_PATH=/usr/lib/jvm/default-java/jre/lib/amd64:/usr/lib/jvm/default-java/jre/lib/amd64/server

Now I can load rJava in both R command line and Rstudio. Thanks for the tip!

Upvotes: 3

Heisenberg
Heisenberg

Reputation: 8806

Thanks to @hrbrmstr's comment, I searched for LD_LIBRARY_PATH in RStudio Support forum and came across this solution.

The issue did boil down to Rstudio being unable to find libjvm.so. I set LD_LIBRARY_PATH in /etc/environment, thus library(rjava) can be loaded via terminal R. However, Rstudio doesn't look into etc/environment and thus is not aware of LD_LIBRARY_PATH.

The upshot: Set LD_LIBRARY_PATH in ~/.profile to make it available to all desktop application (as suggested by Ubuntu wiki article on persistent environment variable)

export LD_LIBRARY_PATH=/usr/lib/jvm/java-7-oracle/lib/amd64:/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server

Then

sudo R CMD javareconf

Upvotes: 7

Related Questions