Search code examples
rrjava

rJava fails to install (MacOS, Red Hat)


I am experiencing the same rJava problem that many other people seem to of had at one point or another. The error occurs when R CMD INSTALL tests whether JNI programs can be compiled.

The output recommends running R CMD javareconf -ed or sudo R CMD javareconf The output of the latter is :

computer: home$ sudo R CMD javareconf
Java interpreter : /usr/bin/java
Java version     : 1.6.0_31
Java home path   : /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
Java library path: 
JNI linker flags : -framework JavaVM
JNI cpp flags    : -I$(JAVA_HOME)/include

Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.

And when trying to install rJava afterwards,

computer: home$ R CMD INSTALL ~/Downloads/rJava_0.9-4.tar.gz 
* installing to library ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library’
* installing *source* package ‘rJava’ ...
checking for gcc... gcc -arch x86_64 -std=gnu99
checking for C compiler default output file name... a.out
/* Passes all checks */
configure: checking whether gcc -arch x86_64 -std=gnu99 supports static inline...yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver    : '/usr/bin/jar'
compiler    : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags   : '-I/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include'
java libs   : '-framework JavaVM'
checking whether JNI programs can be compiled... configure: error: Cannot compile a simple JNI program. See config.log for details.

Make sure you have Java Development Kit installed and correctly registered in R.
If in doubt, re-run "R CMD javareconf" as root.

ERROR: configuration failed for package ‘rJava’
* removing ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library/rJava’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library/rJava’

An alternative attempt where /usr/bin/javac is replaced by /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Homefails just the same.

I am running Mac OS 10.7.3 and

computer: home$ java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-415-11M3646)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-415, mixed mode)

The following is in my .bash_profile

export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

Additionally, I have the same problem on Red-Hat. I hope any fix provided will work there too, but if it won't and why it won't is know, please explain.

I've been using this site's incredible knowledge base for a couple of years now, but this is my first post. Mucho thanks in advance.

Some (not all) of the resources I have already browsed through are

Please note that the apt-get solution in the last link is of no use to me (I think) unless there is an equiv solution for port and/or yum.


Solution

  • I am using Redhat Linux 7.1

    I was getting the same problem as above and I performed the following steps

    1) Edit /usr/lib64/R/etc/Renviron and add "CPPFLAGS=${CPPFLAGS-'-ldl'}" to the end of the file

    2) Then find the java home and set it like below ( set java home till /jre)

    $export JAVA_HOME=/usr/lib/jvm/java-1.7.1-ibm-1.7.1.3.10-1jpp.1.el7_1.x86_64/jre
    $export PATH=$PATH:$JAVA_HOME/bin
    $R CMD javareconf
    

    3) invoke R from commandline

    $R
    > install.packages("rJava")
    > install.packages("RJDBC",dep=TRUE)
    > q()
    Save workspace image? [y/n/c]: y