0
votes

After many infuriating tries getting rJava to work, I've decided to do an Q&A of how I finally got it to work.

How do I install rJava on my MacOS system? I use macOS Catalina 10.15.6.

I frequently get warning messages of the type:

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.5/Resources/library/rJava/libs/rJava.so': dlopen(/Library/Frameworks/R.framework/Versions/3.5/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.5/Resources/library/rJava/libs/rJava.so Reason: image not found

I've previously tried installing different JDK (Java Development Kit) from Oracle. I get the warning that RStudio only wants to work together with JDK-11.0.1. To download this I would need to create an Oracle account.

1
as well as installing the JDK creating a free account might be worth it to get java running, have you tried install.packages(rJava, dependencies = TRUE)Daniel Jachetta

1 Answers

0
votes

I've managed to solve this issue through the following steps:

  1. Remove the package rJava. In the R console, enter:
rm.packages("rJava")
  1. Remove previous attempts to install Java on your MacOS by entering the following in the terminal:
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane 
sudo rm -fr /Library/Application\ Support/Oracle/Java

Solution to remove unwanted previous version: https://stackoverflow.com/a/50056979/11550980

sudo rm -fr /Library/Java/JavaVirtualMachines/jdkmajor.minor.macro[_update].jdk
  1. Install OpenJDK ready for production: JDK 14.0.2

http://jdk.java.net/14/

If installing manually, unpack the .tar.gz file and place the unpacked folder in: /Library/Java/JavaVirtualMachines/

  1. Control in the terminal:
java -version
  1. In the R Console:
install.packages("rJava")
  1. You may have to reconfigure R to work with your version of Java. In the terminal:
R CMD javareconf