简体   繁体   中英

Failure in loding rJava library in R on MacOs

After updating the new MacOs, the system add a new preferred shell zsh., if you have a problem of the shell like reminding you to switch bush or zsh in beginning of terminal, please referring to https://www.theverge.com/2019/6/4/18651872/apple-macos-catalina-zsh-bash-shell-replacement-features

For rJava error which I countered after updating system, many people have this same problem like

    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.6/Resources/library/rJava/libs/rJava.so':
      dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
      Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so
      Reason: image not found

and it couldn't run sudo R CMD javareconf to reset the path.

This topic has already been discussed at ( https://github.com/rstudio/rstudio/issues/2254 ) and the basic approach to solving this problem is at ( https://zhiyzuo.github.io/installation-rJava/ )

However this post is little bit old and inapplicable for the new mac system.

Personally, you need to install the "Homebrew" function at terminal with

    ~$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)

The next step need you to install brew and gcc, but remember you need to install gcc 7.2.0. to do this you need to type this in terminal

~$ brew install gcc@7 

and rename the motherfolder to gcc, and change the inner folder name to 7.2.0 so the pathway should be `/usr/local/Cellar/gcc' (Command+Shift+Dot to show hidden folder)

You need to install the Java SE Development Kit 11.0.1 to fit rJava. link is ( https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html ) search 11.0.1 in the page and you can download it, no specific requirement for Java you can download the updated one here ( https://www.oracle.com/java/technologies/javase-downloads.html )

After you installed the java you can start from step4 for the instruction ( https://zhiyzuo.github.io/installation-rJava/ ) and after you do all the thing remember to run sudo R CMD javareconf to reconfigure the R

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM