Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install rJava on centOS

Tags:

r

rjava

I have a problem installing rJava on a centOS VM (cloudera cdh3u4).

I did this first: sudo R CMD javareconf

[cloudera@localhost ~]$ sudo R CMD javareconf
Java interpreter : /usr/bin/java
Java version     : 1.6.0_31
Java home path   : /usr/java/jdk1.6.0_31/jre
Java compiler    : /usr/bin/javac
Java headers gen.:
Java archive tool: /usr/bin/jar
Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm
JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux

Updating Java configuration in /usr/lib64/R
Done.

But I get this out when I'd like to install rJava:

> install.packages( c('rJava'),
+ repos='http://cran.revolutionanalytics.com')

    ...
    configure: error: One or more Java configuration variables are not set.
    Make sure R is configured with full Java support (including JDK). Run
    R CMD javareconf
    as root to add Java support to R.

    If you don't have root privileges, run
    R CMD javareconf -e
    to set all Java-related variables and then install rJava.

    ERROR: configuration failed for package ‘rJava’
    * removing ‘/home/cloudera/R/x86_64-redhat-linux-gnu-library/2.15/rJava’

    The downloaded source packages are in
            ‘/tmp/RtmpR5V6t5/downloaded_packages’
    Warning message:
    In install.packages(c("rJava"), repos = "http://cran.revolutionanalytics.com") :
      installation of package ‘rJava’ had non-zero exit status

I'm not sure but does it mean that I need to install JDK? If yes, do you know a good site where I find a step-by-step info to install the right JDK for my case? (My final purpose is to install rhdfs and rjava is a needed dependency for that)

like image 608
SWR Avatar asked Nov 14 '12 08:11

SWR


2 Answers

Try this it worked for me get over the configuration problem http://www.ibm.com/support/knowledgecenter/SSPT3X_3.0.0/com.ibm.swg.im.infosphere.biginsights.install.doc/doc/install_install_r.html

I struggled installing rJava and had few learning. Let me explain. When you issue the install package command in R

install.packages("rJava")

Look for the following varaibles set in the R env.

checking Java support in R... present: interpreter : '/usr/java/jdk1.8.0_111/jre/bin/java' archiver : '/usr/java/jdk1.8.0_111/jre/../bin/jar' compiler : '/usr/java/jdk1.8.0_111/jre/../bin/javac' header prep.: '/usr/java/jdk1.8.0_111/jre/../bin/javah' cpp flags : '-I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux' java libs : '-L/usr/java/jdk1.8.0_111/jre/lib/amd64/server -ljvm -ldl'

My java was installed /usr/java/jdk1.8.0_111. Verify if every path specified by variables is correct. Next look for you LD_LIBRARY_PATH. I think it looks for "libjvm.so" in this path. For me it was

export LD_LIBRARY_PATH=/usr/lib/jvm/jdk1.8.0_111/jre/lib/amd64/server:/usr/lib/jvm/jdk1.8.0_111/jre/lib/amd64/

set your JAVA_HOME env variable

First issue the command

R CMD javareconf -e

It will set the following variables JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH modify the JAVA_LIBS directory

export JAVA_LIBS="$JAVA_LIBS -ldl"

Again issue javareconf command without -e

R CMD javareconf

Now enter into R shell and issue the rJava install command and it should find all the env variables and it should work.

like image 96
Anil K Avatar answered Sep 24 '22 04:09

Anil K


Yes you do need the JDK.

For what it is worth, my Debian / Ubuntu package installs openjdk-6-jdk when building our r-cran-rjava package.

And it looks like the java-1.6.0-openjdk.x86_64 package should work for you, you can also try java-1.7.0-openjdk.x86_64.

like image 29
Dirk Eddelbuettel Avatar answered Sep 24 '22 04:09

Dirk Eddelbuettel