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.
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).
You need to unset the JAVA_HOME environmental variable before starting R:
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:If the output is
rw-------
orrw-rw----
then simple users won't be able to read it. You can correct that with thechmod
command: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.