R: rJava package install failing

2019-01-01 08:41发布

When installing rJava using the install.packages("rJava") command I get the following error:

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/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include -I/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include/linux'
java libs   : '-L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/amd64/server -L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/amd64 -L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm'
checking whether JNI programs can be compiled... yes
checking JNI data types... configure: error: One or more JNI types differ from the corresponding native type. You may need to use non-standard compiler flags or a different compiler in order to fix this.
ERROR: configuration failed for package ‘rJava’

I have the Java JDK installed and java -version returns the following:

$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)

When Googling around for the error I see that others are having the same issue but not finding a solution other than "install the whole JDK, not just the JRE" which I have done.

The other thing I read was to run sudo R CMD javareconf which runs quite happily with no errors.

Any ideas what my problem is?

[[EDIT]] It's been a few months since I had this problem. I had initially solved this by editing my Java paths, as illustrated in the answer I posted below. I recently ran into the same issue on a new Ubuntu install. I tried Dirk's recommendation to use apt-get to install the rJava package. It worked perfectly. What I failed to appreciate initially is that installing packages using the Ubuntu apt-get method is fundamentally different than just loading the same package using install.packages() inside of R. The Ubuntu packages solve some issues which I didn't realize or appreciate.

标签: r rjava
15条回答
孤独寂梦人
2楼-- · 2019-01-01 08:47

what I do is here:

  1. in /etc/apt/sources.list, add:

    deb http://ftp.de.debian.org/debian sid main

Note:the rjava should be latest version

2 run: sudo apt-get update sudo apt-get install r-cran-rjava

Once update the old version of rjava, then can install rhdfs_1.0.8.

查看更多
无与为乐者.
3楼-- · 2019-01-01 08:49

Turns out my problem was an issue with my JAVA_HOME environment variable. Yes, shocking I know. My initial setting for PATH and JAVA_HOME looked like this:

export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin

And I added /jre so it now looks like this:

export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export PATH=$PATH:$JAVA_HOME/bin

Everything in Java seemed to work fine without the /jre but rJava would not. Odd.

查看更多
低头抚发
4楼-- · 2019-01-01 08:49

Thanks - your suggestion about $JAVA_HOME lead me to a similar solution:

prompt$ unset JAVA_HOME

before invoking R.

查看更多
不再属于我。
5楼-- · 2019-01-01 08:51

I came across the same issue, and it worked after running commands below.

export JAVA_LIBS="$JAVA_LIBS -ldl"
R CMD javareconf

See details at http://www-01.ibm.com/support/knowledgecenter/SSPT3X_3.0.0/com.ibm.swg.im.infosphere.biginsights.install.doc/doc/install_install_r.html

查看更多
零度萤火
6楼-- · 2019-01-01 08:52

What worked for me was changing JAVA_HOME from file /usr/lib/R/etc/javaconf

I first checked what was my version of Java enabled : sudo update-alternatives --config java. In my case, it was java-8-oracle

I opened the file /usr/lib/R/etc/javaconf and replaced default-java by java-8-oracle :

${JAVA_HOME=/usr/lib/jvm/default-java}

replaced by :

${JAVA_HOME=/usr/lib/jvm/java-8-oracle}

And then sudo R CMD javareconf

I restarted RStudio, and could then install rJava.

查看更多
倾城一夜雪
7楼-- · 2019-01-01 08:57

This worked for me on Ubuntu 12.04 and R version 3.0

cd /usr/lib/jvm/java-6-sun-1.6.0.26/include

this is the directory that has jni.h

Next create a soft link to another required header file (I'm too lazy to find out how to include more than one directory in the JAVA_CPPFLAGS option below):

sudo ln -s linux/jni_md.h .

Finally

sudo R CMD javareconf JAVA_CPPFLAGS=-I/usr/lib/jvm/java-6-sun-1.6.0.26/include
查看更多
登录 后发表回答