54

I am not able to call rJava package in R 3.0. I got the following message

Error: package ‘rJava’ was built before R 3.0.0: please re-install it

I am getting error when I tried to re-install rJava package. I have provided the output of R CMD javareconf

Java interpreter : /usr/bin/java
Java version     : 1.7.0_21
Java home path   : /usr/lib/jvm/java-7-openjdk-i386/jre
Java compiler    : /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/javac
Java headers gen.: /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/javah
Java archive tool: /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/jar

trying to compile and link a JNI progam 
detected JNI cpp flags    : 
detected JNI linker flags : 
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG      -fpic  -O2 -pipe -g  -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
compilation terminated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program


Java library path: 
JNI cpp flags    : 
JNI linker flags : 
Updating Java configuration in /usr/lib/R
Done.

I am using Ubuntu 13.04. I also tried apt-get install r-cran-rjava which is not helping to solve the issue. Regarding jni.h there were some solution here. But, not sure how can I use the solution here.

Community
  • 1
  • 1
vinux
  • 965
  • 1
  • 10
  • 16

4 Answers4

76

I ran into the exact same issue. My solution was to install the openjdk-7-* via

sudo apt-get install openjdk-7-*

Followed that with

sudo R CMD javareconf

and I was then able to install rJava in R via install.packages("rJava").

While perhaps not the most elegant solution it appears to have solved my problems with getting rJava to work.

Peter
  • 7,460
  • 2
  • 47
  • 68
  • 2
    Thank you. It worked. I have tried installing java yesterday.I also tried Oracle Java, but didn't work. Not sure I was installing JRE or reboot did the trick. – vinux May 09 '13 at 04:00
  • 9
    no luck for me: first two steps run without error, then on `install.packages` I get: `error: unable to load shared object '/home/cboettig/R/x86_64-pc-linux-gnu-library/3.0/rJava/libs/rJava.so':` `libjvm.so: cannot open shared object file: No such file or directory`. Any ideas? – cboettig Sep 03 '13 at 17:20
  • 7
    I ran into the same problem - didn't work. Finally found that after installing Java 1.7, I had to tell Ubuntu to use that as default - see [here](http://askubuntu.com/questions/64329/how-to-replace-openjdk-6-with-openjdk-7) - using `update-java-alternatives -l` to get list of java versions installed and `sudo update-java-alternatives -s java-1.7.0-openjdk-i386` to default to 1.7. After this, `sudo R CMD javareconf` ran without error and I was able to `install.packages("rJava")` – JohnSG May 21 '14 at 18:06
  • 4
    For those looking at this more recently try `sudo apt-get install openjdk-8-*` – Michael Plazzer Mar 30 '17 at 01:45
27

For those getting the error:

error: unable to load shared object '/some/dir/rJava/libs/rJava.so': libjvm.so: 
cannot open shared object file: No such file or directory

I solved the error locating the library in the system and linking them to /usr/lib:

$sudo updatedb
$locate libjvm.so
/usr/lib/debug/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/debug/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/jamvm/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
$sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib/ 
kahlo
  • 2,314
  • 3
  • 28
  • 37
2

Installing rJava from the distribution packages as proposed in this askUbuntu answer also works:

sudo apt-get install r-cran-rjava

NOTE: tried from a Debian system.

atfornes
  • 468
  • 5
  • 21
0

I was also facing same error which was on RHEL8.1 & i resolved it as follows:

yum --enablerepo=* install java-1.8* 

later i ran same command which was giving me error logs of R server.

R CMD javareconf

which turns into following output.

enter image description here

Santosh Garole
  • 1,419
  • 13
  • 23