trouble installing and loading rJava on mac El Capitan
Asked Answered
R

5

6

Have issue installing rJava, tried most troubleshooting steps here and doesn't work.

It's returning error

Loading required package: rJava
Error: package or namespace load failed for 'rJava':
 .onLoad failed in loadNamespace() for 'rJava', details:
 call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object     '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/    rJava.so':

I'm on latest ver of R/Rstudio and Mac El Capitan

I also tried this method 1 which didn't work

sudo R CMD javareconf

Then, in the R interpreter:

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

method 2

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

error returned ln: /usr/local/lib/libjvm.dylib: File exists

method 3 install.packages("rJava", type = "binary") error: tar: Failed to set default locale

to deal with default locale error

system("defaults write org.R-project.R force.LANG en_US.UTF-8")

upon loading rJava, still same error:

image not found

So looks like it's installed but won't load

Rapeseed answered 20/5, 2017 at 2:7 Comment(3)
There are far more SO threads than that one: stackoverflow.com/…Cavell
thanks for the reply, I actually tried many of them, nothing works so farRapeseed
I've just written a short note on this and hope it is helpful: zhiyzuo.github.io/installation-rJavaLancastrian
G
-1

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')
Grugru answered 15/7, 2018 at 16:33 Comment(0)
B
7

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")
Batha answered 20/10, 2017 at 21:21 Comment(1)
This method worked for me. But I symlinked from the framework's /lib directory to the already symlinked /usr/local/lib/libjvm with ln -s /usr/local/lib/libjvm.dylib ./ rather than directly into tha java 8 directory.Hunley
H
4

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
Hy answered 18/11, 2017 at 12:44 Comment(0)
E
3

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)
Eduction answered 14/6, 2017 at 12:2 Comment(2)
your solution doesn't work: Error: package or namespace load failed for ‘rJava’: .onLoad failed in loadNamespace() for 'rJava', details: (...)Batha
After step (1), rather than set environment variables to tune the path, you could set an additional symlink in the /Library/Frameworks/R.framework/Versions/3.4/Resources/lib directory to the /usr/local/lib/libjvm.dylib file: ln -s /usr/local/lib/libjvm.dylib /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/Hunley
B
1

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.

Battleplane answered 8/4, 2018 at 18:58 Comment(0)
G
-1

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')
Grugru answered 15/7, 2018 at 16:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.