I'll just add one more possible solution, since I tried all of the suggestions listed above (reinstalling Java x64, installing both JDK & JRE, setting JAVA_HOME, sudo R CMD javareconf
or even sudo R CMD javareconf -n
seen elsewhere, and more) but none of them worked and I kept getting the following error:
> library(rJava)
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so
Reason: image not found
There were 2 possible solutions that helped me get through this error:
- Go to the location of your Java installation (in my Mac OS it was
/Library/Java/JavaVirtualMachines/
) where you'll find a folder titled something like "jdk-13.0.1.jdk" (depending on your JDK version). Changing its name to "jdk-11.0.1.jdk" (or whatever is mentioned in your error) should solve your problem.
But maybe even better is to do the following instead:
- Go to the file referenced in the error:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so
, open it in a text editor (such as TextEdit) and change "jdk-11.0.1.jdk" to "jdk-13.0.1.jdk" (or whatever is the folder referenced in your error and what is actually in your Java folder, respectively).
Either way worked for me but the latter looks a bit cleaner to me.
Hope this helps someone!