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

2
  • 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. Commented Oct 21, 2014 at 15:24
  • @hrbrmstr - not allowed to access that area on the forum. Commented Feb 24, 2020 at 18:22

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Actually you can't set LD_LIBRARY_PATH in .profile in Ubuntu. You can only set it in an interactive shell. More on that: bugs.launchpad.net/ubuntu/+source/xorg/+bug/366728 and help.ubuntu.com/community/EnvironmentVariables. Apart from that the answer is OK
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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.