30

I am trying to load 'rJava' package in my Unix machine. Before loading I have set the path using

Sys.setenv("JAVA_HOME= myfilepath") 

in my R script.

Despite this I am getting the following error (Below is the part of the error):

checking Java support in R... present:
interpreter : '/usr/lib/jvm/jre/bin/java'
archiver    : '/usr/lib/jvm/jre/../bin/jar'
compiler    : '/usr/lib/jvm/jre/../bin/javac'
header prep.: '/usr/lib/jvm/jre/../bin/javah'
cpp flags   : '-I/usr/lib/jvm/java/include I/usr/lib/jvm/java/include/linux'
java libs   : '-L/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/server -ljvm'
checking whether Java run-time works... ./configure: line 3729: /usr/lib/jvm/jre/bin/java: No such file or directory
no configure: error: Java interpreter '/usr/lib/jvm/jre/bin/java' does not work

As you can see the error shows that /usr/lib/jvm/jre/bin/java: No such file or directory. But I have not set this as myfilepath. How do I prevent the installer from looking at this path?

Kindly help.

Aman Mathur
  • 709
  • 2
  • 15
  • 27
  • 1
    Take a look [here](http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing) maybe. There are some good tips there. – David Arenburg Jun 01 '15 at 11:33
  • I had check that post before posting the question. I tried everything there. Does not seem to work for me. – Aman Mathur Jun 01 '15 at 11:56
  • 12
    Did you tried `sudo R CMD javareconf` I had the same problem. rJava trying to check the directories which is not at all there in my system. But after running the above config command, it worked for me. – Manoj G Jul 29 '15 at 02:06
  • thanks Manoj sudo R CMD javareconf worked for me. – gladmax Sep 29 '15 at 03:24

3 Answers3

78
sudo R CMD javareconf

This works perfectly. Keeping this here if someone reads this in future.

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
Sushant Gupta
  • 1,487
  • 2
  • 16
  • 23
  • 2
    This didn't have any effect for me (Mint 18). – CoderGuy123 Aug 25 '16 at 02:32
  • @Deleet Worked for me (Ubuntu Server 16.04) , after I installed openjdk-7-jdk – ZN13 Dec 21 '16 at 14:23
  • Worked for me, ubuntu 16.04.2! – quintindk Jul 14 '17 at 07:42
  • For this to work you need to have java installed first. See here for instructions: https://stackoverflow.com/questions/14788345/how-to-install-jdk-on-ubuntu-linux – joaoal Dec 08 '17 at 09:25
  • 1
    After `sudo R CMD javareconf`, run `sudo rstudio-server restart`. – Leo Jan 25 '18 at 08:09
  • Also note that as of version 0.9-12(2020-03-23) rJava has an --enable-dynload option to enable dynamic loading of the JVM. The changelog also shows the order rJava uses to search for the JVM which might be useful. https://github.com/s-u/rJava/blob/master/NEWS – 2D1C Apr 06 '20 at 15:03
3

I have a VM of Ubuntu 14.04 LTS on VirtualBox, and the real path of installation of my java-jdk is the following :

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

This command worked very fine for my situation. I had this type of error from installation o rJava package on RStudio:

*./configure: line 3736: /usr/lib/jvm/default-java/jre/bin/java: No such file or directory*

First I' have modified the profile in this way : sudo gedit /etc/profile and then added this instructions at the eof:

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH

After this, from terminal session I've typed the command:

sudo R CMD javareconf

and the package rJava was successfully installed.

Note: You might also have to set the LD_LIBRARY_PATH environment variable, before running sudo R CMD javareconf.

Zerodf
  • 2,208
  • 18
  • 26
0

Faced same problem in Ubuntu 14.04. This installation guide was helpful for me after going through a straightforward installation. http://www.korecky.org/?p=1254 (Installation of R) and [http://www.korecky.org/?p=847] (Installation of Java)

MItrajyoti
  • 508
  • 9
  • 14
  • Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. – pableiros Dec 13 '16 at 15:21