6

I have a terrible time installing the package in R while I am using a Mac with M1 architecture.

Here are the steps I have followed so far

  1. install Java https://www.azul.com/downloads/?os=macos&architecture=arm-64-bit&package=jdk, using the version Zulu: 16.30.19

  2. install.packages("rJava") in R

  3. R CMD javareconf in terminal

  4. dyn.load("/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/server/libjvm.dylib") in R

  5. library(rJava)

This is my error

Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(jvm, FALSE)
  error: unable to load shared object '/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/server/libjvm.dylib':
  dlopen(/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/server/libjvm.dylib, 10): no suitable image found.  Did find:
    /Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/server/libjvm.dylib: mach-o, but wrong architecture
    /Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/server/libjvm.dylib: mach-o, but wrong architecture

Any help is be appreciated

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
LDT
  • 2,856
  • 2
  • 15
  • 32

3 Answers3

4

I had the same problem as you but managed to get it going after finding this burried in some documetation.

To use Java (specifically, package rJava) with a CRAN (‘x86_64’) binary distribution of R on ‘arm64’ macOS install a ‘x86_64’ build of a Java JRE such as that from AdoptOpenJDK, then run sudo R CMD javareconf.

To see what compatible versions of Java are currently installed, run /usr/libexec/java_home -V -a x86_64. If needed, set the environment variable JAVA_HOME to choose between these, both when R is built from the sources and when R CMD javareconf is run.

Configuring and building R both looks for a JRE and for support for compiling JNI programs (used to install packages rJava and JavaGD); the latter requires a JDK (Java SDK) and not just a JRE99.

https://cran.r-project.org/doc/manuals/r-patched/R-admin.html

Levon Rush
  • 55
  • 5
  • 2
    A god send. Downloading the arm64 version of R 4.1.2 (from CRAN) and installing over the x86_64 version solved this issue. – kentkr Mar 02 '22 at 21:49
  • 1
    @Levon Rush, could you transform this response into a step-by-step tutorial? Sorry, I couldn't follow it through, but I think this is exactly what I need. Thank you – Ruam Pimentel Nov 25 '22 at 00:51
4

The way I got things working well enough to use the packages I needed (e.g., tabulizer--see here) was by backing all the way down to Java 8. To get a matching arm64 build, this means getting Java from Azul, since Oracle doesn't (yet?) put out one for that version.

Frederick Solt
  • 356
  • 3
  • 10
  • 1
    This REALLY helped. I had installed Java 11 through conda. Downgrading to Java 8, running `R CMD javareconf` and re-installing rJava worked for me! – dayne May 04 '22 at 19:40
1

This worked for me

  • Install the latest stable version of R from CRAN (tested on 4.3.1 (2023-06-16))
  • Install a x86_64 build of Java (version 17 - it does not seem to work with versions 8 or 11) with brew tap homebrew/cask-versions && brew install --cask temurin17
  • Add it to PATH with export JAVA_HOME=$(/usr/libexec/java_home -v 17)
  • run sudo -E R CMD javareconf

Then open R and install.packages('rJava') should work

Shinobi_Atobe
  • 1,793
  • 1
  • 18
  • 35