trouble installing and loading rJava on mac El Capitan

放肆的年华 提交于 2019-11-29 04:36:30

The problem was rJava wont install in RStudio (Version 1.0.136). The following worked for me (macOS Sierra version 10.12.6) (found here):

Step-1: Download and install javaforosx.dmg from here

Step-2: Next, run the command from inside RStudio:

install.packages("rJava", type = 'source')

Here is my solution

Define path to R libraries, here R 3.4 version and open dir:

cd /Library/Frameworks/R.framework/Versions/3.4/Resources/lib

Remove libjvm.dylib:

rm libjvm.dylib

Create link to libjvm.dylib from Java libraries, here jdk1.8.0_151 version:

ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/server/libjvm.dylib libjvm.dylib

now go to R or RStudio and try:

library("rJava")

I did the same thing for java 9, it worked perfectly (macOS High Sierra), thanks:

cd /Library/Frameworks/R.framework/Versions/3.4/Resources/lib
rm libjvm.dylib
ln -s /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/lib/server/libjvm.dylib libjvm.dylib
sgaw

I also had a lot of trouble with this and eventually found the following SO thread to be the most relevant: rJava load error in RStudio/R after "upgrading" to OSX Yosemite

Basically, starting from no installation of rJava, and starting in the terminal:

  1. Form the sym link (note, the -f flag will overwirte existing links avoiding the error you encountered in "method 2".

$ sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib

Then in RStudio:

  1. Ensure options('java.home') isn't NULL, and set if necessary:

options("java.home"="/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre")

  1. Ensure the JAVA_HOME and LD_LIBRARY_PATH environment variables are set, and set if not:

Sys.setenv(JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home') Sys.setenv(LD_LIBRARY_PATH='$JAVA_HOME/jre/lib/server')

After this I was able to install and load the rJava package in RStudio with

install.packages('rJava')
library(rJava)

I have tried most of the recommendations on this site, but none worked. The only working solution for me was on this Github site site.

Hope this solves your issues.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!