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)

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

      1. am getting below error while installing xlsx package, someone help me to get resolve.

        * installing *source* package ‘xlsx’ …
        ** package ‘xlsx’ successfully unpacked and MD5 sums checked
        ** R
        ** inst
        ** preparing package for lazy loading

        *** caught bus error ***
        address 0x7ffe6dc79ef8, cause ‘non-existent physical address’

        An irrecoverable exception occurred. R is aborting now …
        /usr/lib64/R/bin/INSTALL: line 34: 33398 Done echo ‘tools:::.install_packages()’
        33399 Bus error (core dumped) | R_DEFAULT_PACKAGES= LC_COLLATE=C “${R_HOME}/bin/R” $myArgs –slave –args ${args}

        The downloaded source packages are in

  1. 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) 🙂

  2. This was really helpful, thanks! When running from the command line I found it important to specific whether to run from /bin or /bin/x64. If Java is 64 bit, use the latter.

  3. > Sys.setenv(JAVA_HOME=’C:Program FilesJavajre7′) # for 64-bit version
    > Sys.setenv(JAVA_HOME=’C:Program Files (x86)Javajre7′) # for 32-bit version
    > library(rJava)

    Error : .onLoad failed in loadNamespace() for ‘rJava’, details:
    call: inDL(x, as.logical(local), as.logical(now), …)
    error: unable to load shared object ‘C:/Users/ryusukekenji/Documents/R/win-library/2.15/rJava/libs/x64/rJava.dll’:
    LoadLibrary failure: %1 is not a valid Win32 application.

    I am using 64bit windows, tried to install 64bit Java and also 32bit Java but keep giong error… May I know how to solve this problem?

    1. Hey, I am also having toruble with the same issue. Anything which solves it? Had no issues running rJava before but now the same error message pops up after fixing the problem with the environment.

  4. Thank you so much! Finally someone who can explain a complicated-seeming topic in a very comprehensive manner – I´ve been trying to “uncode” the things that were written about changing directories and stuff on other pages but never was successful – now it worked out in 5 minutes! You save my day 😉

  5. for the commands

    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

    make sure that the path to your Java Jre is correct, for example in my Window OS the correct path is:
    Sys.setenv(JAVA_HOME=’C:\\Program Files\\Java\\jre1.8.0_73′)

  6. Tal, this is really helpful…crisp and clear! “Manually downloading and installing Java for 64-bit” is the key – atleast for me. Thanks much!!! 🙂

  7. I detest this package. I’ve given up trying to use it, because the installation is incredibly complex, and leads to an endless series of errors. Whomever wrote this needs to have a step-by-step instruction guide.

  8. Hi,

    Just a short note about what worked for me – Just adding the jdk path (instread of jre):
    Sys.setenv(JAVA_HOME=’C:\\Program Files (x86)\\Java\\jdk1.8.0_121′)
    Sys.getenv(‘JAVA_HOME’)
    [1] “C:\\Program Files (x86)\\Java\\jdk1.8.0_121”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.