4

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

Community
  • 1
  • 1
Heisenberg
  • 8,386
  • 12
  • 53
  • 102
  • RStudio does not run R code. It is an IDE. R still runs the code. If there are RStudio-specific issues, you might want to use their support forum. This issue [seems to be handled there](https://support.rstudio.com/hc/communities/public/questions/200645248-Setting-up-LD-LIBRARY-PATH-for-a-rsession). – hrbrmstr Oct 21 '14 at 15:24
  • @hrbrmstr - not allowed to access that area on the forum. – John M Feb 24 '20 at 18:22

2 Answers2

7

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
Heisenberg
  • 8,386
  • 12
  • 53
  • 102
  • Actually you can't set LD_LIBRARY_PATH in .profile in Ubuntu. You can only set it in an interactive shell. More on that: https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/366728 and https://help.ubuntu.com/community/EnvironmentVariables. Apart from that the answer is OK – haddr Apr 15 '15 at 22:59
3

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!

Sam
  • 791
  • 6
  • 9