8

I am relatively new to Ubuntu so I wont know a lot of commands that probably became standard to a lot of you guys. I am trying to set up R and with it the necessary java dependencies to install e.g. JGR, rjava, etc. I read through quite a few instructions to do that but somehow I must have done sth wrong. Here is the state of R and java:

R --version

R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)

java -version

java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

R CMD javareconf

Java interpreter : /usr/bin/java
Java version     : 1.6.0_23
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
Java library path: /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-6-openjdk/jre/lib/amd64:/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib
JNI linker flags : -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm
JNI cpp flags    : 

But when I try to install 'JavaGD' in R, which is a dependency for JGR I get:

...
checking Java support in R... present:
interpreter : '/usr/bin/java'
cpp flags   : ''
java libs   : '-L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm'
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.
...

Any help would be greatly appreciated. Thanks!

5 Answers 5

7

I'm not familiar with R but based on your console it seems like R is requiring a JDK while you have a JRE as you default JAVA home variable. I would suggest you to make sure you have the JDK installed or install it (sudo apt-get install openjdk-6-jdk).
Also make sure that your JAVA_HOME environment variable is pointing to the JDK and not to the JRE (you can see in your output that currently the java home path is set to /usr/lib/jvm/java-6-openjdk/jre.

3
  • openjdk-6-jdk is installed. When I set the path to /usr/lib/jvm/java-6-openjdk I still get the same error
    – Marco
    Jan 25, 2012 at 7:06
  • yossile advised the path /usr/lib/jvm/java-6-openjdk/jre
    – Panther
    Apr 2, 2012 at 3:04
  • irrelevant answer the import info from the log is the last line : need to be run by root (as mentioned in other replies)
    – Sylvain
    Apr 28, 2016 at 8:51
7

One shouldn't blindly install openjdk-6-jdk. What helped me, was to change the version of Java. Fortunately there is a nice Ubuntu tool for doing that:

sudo update-alternatives --config java

There you can see, what Javas are already available on system, and set the desired one. And then install either openjdk-7-jdk or openjdk-6-jdk (or both)

and only then run

sudo R CMD javareconf

More details about Java choices are on Ubuntu's Community Wiki

P.S. For people coming here from Google: Among other things, this post helps solving issues with rj instalation in R, with error message: R is not configured with full Java support. Please make sure an JDK is installed and run R CMD javareconf. When I did that, it said: NOTE: Your JVM has a bogus java.library.path system property!. So: no need messing with Java's library paths!.

1
  • this worked for me on ubuntu 16.04, but i had to launch R using sudo -i R
    – Imran Ali
    Oct 27, 2017 at 9:27
3

R CMD javareconf as root

means, you have to use sudo, to issue your command:

sudo R CMD javareconf

You will get asked for your password (your normal userpassword).

1
  • all the commands above where executed as root user through sudo -su at the start of the session. Sorry, forgot to mention that.
    – Marco
    Jan 26, 2012 at 0:59
0

Yossiles answer helped me on the way, but here is the newbie-friendly version, which also draws on the answer to this question.

What worked for me was was this:-

1) open /etc/environment in your favorite txteditor:

sudo gedit /etc/environment

2) add a new line with "JAVA_HOME" and the path to correct jr-directory, in the case of java 8, it is:

JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre"

3) source the updated environment and check the variable:

source /etc/environment
echo $JAVA_HOME

4) update the java-R configuration like this:

sudo R CMD javareconf

5) install RJava, XLConnect or whatever java-dependent R-package you are looking for.

0

Yes, update-alternatives is the most convenient linking mechanism to maintain different JVM versions - even from different providers like Oracle / OpenJDK. I am open to correction but I would say one needs a JDK and not only a JVM for R setup.

The outline to prepare for R JAVA configuration are:

  1. ensure that the required JVM is correctly located in /usr/lib/jvm
  2. setup the linking using update-alternatives --install for each JAVA command required by R
  3. use update-alternatives --configure to select a default JVM
  4. refresh the R configuration

To ensure that the JDK is already in the correct location, query the list of installed JVMs with the command

ls /usr/lib/jvm

If the folder does not include a JDK then relocate the entire JVM folder from the extracted tar.gz (download) to /usr/lib/jvm with the command:

sudo mv <JDK folder> /usr/lib/jvm

separate terminal entries for update-alternatives is required by R for the following JAVA commands:

  • interpreter : '/usr/bin/java'
  • archiver : '/usr/bin/jar'
  • compiler : '/usr/bin/javac'
  • header prep.: '/usr/bin/javah'

the entries for jdk1.8.0_51 are as follows:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_51/bin/java" 2

sudo update-alternatives --install "/usr/bin/jar" "jar"  "/usr/lib/jvm/jdk1.8.0_51/bin/jar" 2

sudo update-alternatives --install "/usr/bin/javac" "javac"  "/usr/lib/jvm/jdk1.8.0_51/bin/javac" 2

sudo update-alternatives --install "/usr/bin/javah" "javah"  "/usr/lib/jvm/jdk1.8.0_51/bin/javah" 2

NB. the output after execution of update-alternatives --install for JVM jdk1.8.0_51 should be similar output to:

update-alternatives: using /usr/lib/jvm/jdk1.8.0_51/bin/java to provide /usr/bin/java (java) in auto mode

to select the required JVM as default

sudo update-alternatives --config java

If only a single JVM is setup then the following output is presented in the terminal

There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/jdk1.8.0_51/bin/java Nothing to configure.

alternatively the relevant entry# for the required JVM must be selected

to check that the correct JVM is linked

java --version

finally, update the R setup with:

sudo R CMD javareconf

Note that this setup could not seem to be working if you have attempted other ways to "hardwire" configure your JVM

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .