Henk
Henk

Reputation: 3656

rJava installation in R on debian

After updating to R 3.0.1 on a Debian 64-bit machine, the rJava package does not want to install.

configuration failed, so sudo R CMD javareconf [this worked on another debian machine]. however it does not work here, has anybody else had this problem? [see terminal output below]

henk@crunchbang:~$ sudo R CMD javareconf
Java interpreter : /usr/bin/java
Java version     : 1.6.0_18
Java home path   : /usr/lib/jvm/java-6-openjdk/jre
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar

trying to compile and link a JNI progam 
detected JNI cpp flags    : 
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic  -O3 -pipe  -g  -c conftest.c -o conftest.o
conftest.c:1:17: error: jni.h: No such file or directory
conftest.c: In function ‘main’:
conftest.c:4: warning: implicit declaration of function ‘JNI_CreateJavaVM’
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/lib64/R
Done.

# check java
henk@crunchbang:~$ java -version
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8.13) (6b18-1.8.13-0+squeeze2)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)

java environment:

henk@crunchbang:~$ aptitude search "?provides(java-runtime)"
i A default-jre                            - Standard Java or Java compatible Runtime        
i A default-jre-headless                   - Standard Java or Java compatible Runtime (headle
p   gcj-4.4-jre                            - Java runtime environment using GIJ/classpath    
p   gcj-4.4-jre-headless                   - Java runtime environment using GIJ/classpath (he
p   gcj-jre                                - Java runtime environment using GIJ/classpath    
p   gcj-jre-headless                       - Java runtime environment using GIJ/classpath (he
i A openjdk-6-jre                          - OpenJDK Java runtime, using Hotspot JIT         
i A openjdk-6-jre-headless                 - OpenJDK Java runtime, using Hotspot JIT (headles
i   sun-java6-jre                          - Sun Java(TM) Runtime Environment (JRE) 6 (archit

Upvotes: 3

Views: 2901

Answers (2)

plamtrue
plamtrue

Reputation: 73

I took these steps (on an EC2 with Ubuntu 14.04 and RStudio-Server) to install the R package qdap which requires rJava: (I'm probably quoting other sources here and there and I don't remember from where, but thanks.)

Install these repositories from http://sites.psu.edu/theubunturblog/cran2deb4ubuntu/

(debian: http://r-forge.r-project.org/projects/cran2deb/)

sudo add-apt-repository ppa:marutter/rrutter
sudo add-apt-repository ppa:marutter/c2d4u 
sudo apt-get update

Install Java:

sudo apt-get install openjdk-7-jdk
ls /usr/lib/jvm

Set a system-wide environment variable for Java:

sudo joe /etc/profile.d/javaenvvar.sh

which contains:

# JAVA environment variable
# for openjdk-7-jdk in order to use the R package `qdap`.
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
export PATH=$PATH:$JAVA_HOME/bin

Then exit BASH and sign in again. Check your path changes:

echo $PATH
echo $JAVA_HOME

Then:

sudo R CMD javareconf

Should return:

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

Create the file /etc/ld.so.conf.d/java.conf with the following entries:

/usr/lib/jvm//usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64
/usr/lib/jvm//usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server

Then install rJava from those new repositories:

sudo apt-get install r-cran-rjava

That just installed rJava to /usr/lib/R/site-library which is accessible to all users of RStudio-Server, hopefully.

sudo update-alternatives --config java

Hopefully, there's only one java installed.

Update R packages:

sudo R
> packageStatus()
> update.packages()

Install R packages system wide (still within sudo R):

> install.packages("qdap", lib="/usr/lib/R/site-library")

Reset RStudio-Server:
Sign out of RStudio-Server first.

sudo rstudio-server stop
sudo rstudio-server start

Sign back in to RStudio-Server.

If you get a memory error, try detaching some packages. The EC2 t2-micro has only 1 GB of RAM.

Upvotes: 3

Konstantinos
Konstantinos

Reputation: 11

I had the same problem, the solution was updating to openjdk-7-* and use update-alternatives --config java to set the java-7-openjdk path.

Upvotes: 1

Related Questions