Reputation: 3088
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
install Java https://www.azul.com/downloads/?os=macos&architecture=arm-64-bit&package=jdk, using the version Zulu: 16.30.19
install.packages("rJava")
in R
R CMD javareconf
in terminal
dyn.load("/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/lib/server/libjvm.dylib")
in R
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
Upvotes: 10
Views: 6207
Reputation: 1963
This worked for me
brew tap homebrew/cask-versions && brew install --cask temurin17
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
sudo -E R CMD javareconf
Then open R and install.packages('rJava')
should work
Upvotes: 8
Reputation: 376
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.
Upvotes: 4
Reputation: 65
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
Upvotes: 5