Sunday, December 22, 2013

rJava Package Installation Problem on Linux

Attempting to install the Latent Semantic Analysis "lsa" package for R on Ubuntu, the installation fails due to a problem in the rJava  package which is one of the dependencies for the "lsa".

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 a root to add java support to R

However, following the suggested solution by running R CMD javareconf as root didn't help.  I noticed that output of this commands gives an empty line for JNI CPP FLAGS. The problem still exists after running those commands.

Here is how I managed to solve the problem and get a successful installation of RJava and as a result the other packages that depend on it.

Step1 : Make sure to have JDK installed which can be done by using the following command:
 sudo apt-get install openjdk-7-jdk

Step 2:  Define the JAVA_HOME environmental variable and add the JDK bin path to your PATH variable. You can do this by adding the following lines to the end of the .bashrc under the home directory.

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64

export PATH=$PTH:$JAVA_HOME/bin

To ensure that those commands take effect immediately you can run
source ~/.bashrc

Step 3: First make sure that include/jni.h exist under the JAVA_HOME directory then reconfigure the Java support for R using

sudo R CMD javareconf JAVA_CPPFLAGS=-I$JAVA_HOME/include

Step 4. Reattempt installing RJava in R.