How to load the {rJava} package after the error “JAVA_HOME cannot be determined from the Registry”

In case you tried loading a package that depends on the {rJava} package (by Simon Urbanek), you might came across the following error:

Loading required package: rJava
library(rJava)
Error : .onLoad failed in loadNamespace() for ‘rJava’, details:
call: fun(libname, pkgname)
error: JAVA_HOME cannot be determined from the Registry

The error tells us that there is no entry in the Registry that tells R where Java is located. It is most likely that Java was not installed (or that the registry is corrupt).

This error is often resolved by installing a Java version (i.e. 64-bit Java or 32-bit Java) that fits to the type of R version that you are using (i.e. 64-bit R or 32-bit R). This problem can easily effect Windows 7 users, since they might have installed a version of Java that is different than the version of R they are using.

Note that it is necessary to ‘manually download and install’ the 64 bit version of JAVA. By default, the download page gives a 32 bit version .

You can pick the exact version of Java you wish to install from this link. If you might (for some reason) work on both versions of R, you can install both version of Java (Installing the “Java Runtime Environment” is probably good enough for your needs).
(Source: Uwe Ligges)

Other possible solutions is trying to re-install rJava.

If that doesn’t work, you could also manually set the directory of your Java location by setting it before loading the library:

Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre7') # for 64-bit version
Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre7') # for 32-bit version
library(rJava)

(Source: “nograpes” from Stackoverflow, which also describes the find.java in the rJava:::.onLoad function)

  • john nina

    I read your artcle about“JAVA_HOME cannot be determined from the Registry” i am very impress with you becouse your artcle show you have great knowlage about it so i requet you must share your khowlage is other topic also like this Nokia Mobiles

  • Steve Fleming

    Hallelujah! Thank you for helping me resolve this problem.

    • http://www.r-statistics.com/ Tal Galili

      I’m very happy to read my post helped you :)
      With regards,
      Tal

  • SS

    Helped me too!! I was trying other complicated solutions but none of them worked!
    Thanks. :-)

    • http://www.r-statistics.com/ Tal Galili

      My pleasure :)

  • Rohan

    Try rolling back to Java 1.6. That worked for me

  • boian

    You are the best! Thanks!

    • http://www.r-statistics.com/ Tal Galili

      You’re welcome :)

  • David

    To follow up on your point (and hopefully save others from frustration), it is necessary to ‘manually download and install’ the 64 bit version of JAVA. By default, the download page gives a 32 bit version as described here: http://java.com/en/download/faq/java_win64bit.xml.

    • http://www.r-statistics.com/ Tal Galili

      Thanks David,
      I’ve updated the post accordingly.

  • Kajanan

    Thanks for your help !! Keep going !!

    • http://www.r-statistics.com/ Tal Galili

      You’re welcome :)

  • woof

    Thank you, thank you, this was very helpful. (Needed to manually install 64 bit java for my script to work on a coworker’s windows machine) :)

    • http://www.r-statistics.com/ Tal Galili

      You are welcome Woof :)

  • Pingback: MattF’s ramblings » Blog Archive » R rJava (.jinit()) stops working - make it work again