4

I'm running R 3.0.2 on Ubuntu 14.04.1. I've installed the rJava package, but I can only get it to work in R/RStudio if I launch it with sudo. If I click on the application launcher, or just enter R in the command line, I get the following error when loading the rJava library:

> library(rJava)  
Error : .onLoad failed in loadNamespace() for 'rJava', details:
    call: dyn.load(file, DLLpath = DLLpath, ...)
    error: unable to load shared object '/usr/lib/R/site-library/rJava/libs/rJava.so':
    libjvm.so: cannot open shared object file: No such file or director  
Error: package or namespace load failed for ‘rJava’

However, if I type 'sudo rstudio' or 'sudo R' in a terminal, rJava loads without a problem. Does anybody know what I'm doing wrong?

Possibly related issue: I installed rJava by entering

sudo apt-get install r-cran-rjava

at the command prompt; installing the normal way:

apt-get install r-cran-rjava

did not work for me, and neither did installing from within R (without launching it using sudo). When I tried to install this way, I ran into the same problem as addressed in this question.

Community
  • 1
  • 1
CCC
  • 891
  • 8
  • 9

4 Answers4

4

The file /usr/lib/R/site-library/rJava/libs/rJava.so is probably not readable by any user other than root. You can check that with:

ls -l /usr/lib/R/site-library/rJava/libs/rJava.so

If the output is rw------- or rw-rw---- then simple users won't be able to read it. You can correct that with the chmod command:

chmod -R a+rX /usr/lib/R/site-library/rJava/
damienfrancois
  • 52,978
  • 9
  • 96
  • 110
  • 2
    That seems like it should work, but I'm still getting the same error message (though not when I run R as sudo), even after going too far and changing the permissions to rxwrwxrwx. Maybe there are some dependency files that I need to change as well? – CCC Aug 11 '14 at 16:48
2

I tried the solution listed here to no avail. What worked on Ubuntu 14.04 was to create a soft link to libjvm.so in /usr/lib.

ln -s /usr/lib/jvm/java-8-oracle/jre/lib/amd64/server/libjvm.so /usr/lib 
Pepin_the_sleepy
  • 297
  • 1
  • 13
1

You need to unset the JAVA_HOME environmental variable before starting R:

 unset JAVA_HOME
Gon
  • 11
  • 1
1

Saw this problem when running from Rscript. Sudo worked, Rscript as user did not. I first did chmod -R a+rX as damienfrancois suggested, but that did not work. Then I tried unset JAVA_HOME, as Gon suggested. That worked (or possibly that in combination with the chmod).

caewok
  • 91
  • 1
  • 3