I just went through the difficulty of getting Java working in R/RStudio myself on an M1 Mac. Java installed through Homebrew and Adoptium/Temurin stubbornly did not work for me. It is certainly true that I haven't tried everything, so it's quite possible there are solutions with Homebrew and Temurin that I didn't find because I didn't know what to look for. The solution appeared fairly simple once I got to it.
The key, at least for me, was this advice, according to Andrés Castro Socolich on the Posit Forum (emphasis mine).
check what Java version you have installed in your system (it has to match R's architecture)
Since my R (via R --version
) is aarch64-apple-darwin20
, I visited https://www.oracle.com/java/technologies/downloads/, selected the latest ARM64 DMG Installer for Mac, and installed it.
At some point I had set JAVA_HOME in my shell files, but the original default stanza was correct all along, so that when I put the following in my .zprofile (my shell is zsh)
export JAVA_HOME=$(/usr/libexec/java_home)
opening a new shell puts the following into my environment.
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-23.jdk/Contents/Home
I restarted RStudio and was able to load the OpenStreetMap package without errors.
Can't say this will work for anyone else, since there were multiple JDK installs, R reconfigs, etc., etc. on the way to solving it for myself.
Versions used: