Search code examples
javarrjava

how to set java to use rjava on MacBook pro with m2


I want to install rjava but i got this error i do not know what to do to be able to install

using MacBook Pro with M2

Hope someone help me

install.packages("~/Downloads/rJava_0.9-9.tar.gz", repos = NULL, type = "source")
* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
** using staged installation
checking whether JNI programs can be compiled... configure: error: Cannot compile a simple JNI program. See config.log for details.

Make sure you have Java Development Kit installed and correctly registered in R.
If in doubt, re-run "R CMD javareconf" as root.

ERROR: configuration failed for package `rJava`
* removing ‘/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/rJava’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/rJava’
Warning in install.packages :
  installation of package ‘/Users/hassan/Downloads/rJava_0.9-9.tar.gz’ had non-zero exit status

Solution

  • As you can see from the text (the removing ‘/Library/Frameworks/R.framework/Versions/4.4-x86_64 part), it's trying to install the x86_64 part which is for Intel (or intel clones such as AMD) CPUs.

    Your apple M2 isn't an intel nor an intel clone. The usual architecture name is 'aarch64' or 'arm'. See Apple Silicon M Series in Wikipedia.

    Your problem appears to be that you're attempting to install a really old verison; a version that is not, and probably will never be, released as an aarch64 binary.

    Try installing version 1.0-11 instead. As per r-project.org itself this version is available in 'arm64' which might work. The last update on the rJava git is 4 months ago, with a promising commit message: update setup-java to work on arm64 and set NOAWT - and the README.md seems to say you should be able to use rJava and R on apple M chips. I suggest you very carefully read and follow those instructions.