8

Trying to install the rJava package on R, on my 14.10 ubuntu, using this code

if (!require(rJava)) install.packages('rJava')

got few errors related to java including jni problems, after reinstalling the jdk, and tried to run the same code again, got that error

Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/usr/local/lib/R/site-library/rJava/libs/rJava.so':
  libjvm.so: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/site-library/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpfFjrp0/downloaded_packages’
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘rJava’

looked for solutions, to find just about everyone suggesting (for x64) to execute those commands

export LD_LIBRARY_PATH=/usr/lib/jvm/java-8-oracle/lib/amd64:/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server
sudo R CMD javareconf 

but that didn't work, is there anything else I can do? I will provide any needed details, and searching for libjvm.so on the entire machine resulted in this

/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server/libjvm.so
/usr/lib/jvm/jdk1.8.25/jre/lib/amd64/server/libjvm.so
/usr/local/java/jre1.7.0_75/lib/amd64/server/libjvm.so
1
  • 1
    Had same problem. Executing 'export LD_LIBRARY_PATH=/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server' solved it for me – Juliusz May 11 '15 at 5:12
12

Executing the following should solve your problem:

$ export LD_LIBRARY_PATH=/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server
$ sudo R CMD javareconf
2
  • It worked to me. Thx – JoSeTe4ever May 6 '16 at 9:33
  • 1
    The exact path depends on the java version that is used. For me it was LD_LIBRARY_PATH=/usr/lib/jvm/java-11-openjdk-amd64/lib/server/. – Stibu Feb 13 '20 at 20:52
3

Sometimes you need this R CMD javareconf -e

see https://stackoverflow.com/a/13446026/2803344

1
  • That's what I was missing, thanks! Any way to make it persistent? – Waldir Leoncio Dec 30 '19 at 16:22
2

Steps:

  1. Find your R location. It will be stored in rsession-ld-library-path in rserver.conf file. Or just by doing which R. The location usually is /usr/lib64/R/lib or /usr/lib64/microsoft-r/3.3/lib64/R/lib

  2. Find the libjvm.so file which is usually in the usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server path depending on which jre you're using. Check echo $JAVA_HOME.

  3. Create a symlink using ln -s sudo ln -s /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib64/microsoft-r/3.3/lib64/R/lib/libjvm.so

  4. Restart R server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.