R Error: JAVA_HOME cannot be determined from the Registry (Example)
This article shows how to handle the error message “JAVA_HOME cannot be determined from the Registry” in the R programming language.
The tutorial will contain these content blocks:
Let’s just jump right in.
Example 1: Reproducing the Error: JAVA_HOME cannot be determined from the Registry
In this example, I’ll explain how to replicate the error message “JAVA_HOME cannot be determined from the Registry”.
This error message typically appears when we want to load the xlsx package as shown below:
install.packages("xlsx") # Install & load xlsx library("xlsx") # Loading required package: xlsx # Loading required package: xlsxjars # Loading required package: rJava # Error : .onLoad failed in loadNamespace() for 'rJava', details: # call: fun(libname, pkgname) # error: JAVA_HOME cannot be determined from the Registry # Failed with error: 'package 'rJava' could not be loaded'
As you can see, the error “JAVA_HOME cannot be determined from the Registry” was returned to the RStudio console after installing and loading the xlsx package.
However, this problem does not occur because of the xlsx package, but because of the rJava package.
R tries to install the rJava package as well, when we are installing the xlsx package.
So why does the error message “JAVA_HOME cannot be determined from the Registry” occur when we are trying to install the rJava package?
The reason for this usually is that you are using a 64-bit version of R, but not a 64-bit version of Java.
You may have installed a 32-bit version of Java or you might not have installed Java at all.
Note that the Java download page suggests the 32-bit version by default. Hence, it is necessary to manually install the 64-bit version.
Example 2: Fixing the Error: JAVA_HOME cannot be determined from the Registry
In this example, I’ll explain how to solve the problems when trying load an R package due to rJava.
For this, you have to download and install the 64-bit version of Java on this page: Download Java 64-bit version for Windows.
After installing the 64-bit version of Java, we have to install and load the rJava package (or as in our example the xlsx package) again:
install.packages("xlsx") # Install xlsx package library("xlsx") # Load xlsx package
This time it worked without any issues!
Video & Further Resources
Have a look at the following video which I have published on my YouTube channel. In the video, I’m explaining the content of this article in a live session in RStudio.
The YouTube video will be added soon.
Furthermore, you could read the related articles of my homepage:
In summary: You learned in this article how to fix the error “JAVA_HOME cannot be determined from the Registry” in R programming. If you have additional questions, don’t hesitate to let me know in the comments below.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.







16 Comments. Leave new
SUPER. Thank you Joachim.
Thank you Robert, glad it was helpful! 🙂
thanks a lot, got the same issue. fixed easily using this
This is great to hear Sanchit, glad you found a solution!
thanks
You are very welcome Dennis!
Doesn’t work for me. I get:
“java.home option: PATH TO jre
JAVA_HOME environment variable:
Warning message:
In fun(libname, pkgname) :
Java home setting is INVALID, it will be ignored.
Please do NOT set it unless you want to override system settings.”
Hi Reinout,
It is difficult to help you with this error without seeing your code. Could you please share your code?
Regards,
Joachim
You are amasing ! Your page is always so helpful ! Thanks very much for this nice explanation ! I have to add, that I used this function because it offers the “showNA” parameter, so I’d like you to talk about it. It is not available in the “writexl” package, or the “openxlsx” package so I was getting empty cells.
Hello Maria,
Thank you for your kid words. I understand that you fixed your problem. If you have any further questions, don’t hesitate to ask.
Best,
Cansu
hi boss, been able to install java, xjava but not successful with xlsxjars keeps failing and unable to see the excel file in my folder. any help would be greatly appreciated
been able to download and install java, xjava but unable to install xlsxjars while going through the excel package tutorial. any help would be greatly appreciated
Warning in .rs.downloadFile(url = urls, destfile = destfiles, method = “libcurl”, :
downloaded length 5098969 != reported length 10270611
Warning in .rs.downloadFile(url = urls, destfile = destfiles, method = “libcurl”, :
URL ‘https://cran.rstudio.com/bin/windows/contrib/4.5/xlsxjars_0.9.0.zip’: Timeout of 60 seconds was reached
Error in .rs.downloadFile(url = urls, destfile = destfiles, method = “libcurl”, :
download from ‘https://cran.rstudio.com/bin/windows/contrib/4.5/xlsxjars_0.9.0.zip’ failed
Warning in download.packages(pkgs, destdir = tmpd, available = available, :
download of package ‘xlsxjars’ failed
that is the error am getting when trying to load the xlsxjars package. pls any assistance
Hey,
Thanks for your comments and for sharing your R outputs. I’m not entirely sure why the error is still occurring. It may be worth trying a different package to import your XLSX files.
For example, the readxl package from the Tidyverse is a reliable alternative. You can use it as shown below.
I hope this helps.
Regards,
Joachim
ok will try and get back to you
Sounds good. 🙂
Regards,
Joachim