无法在 R 中安装 rJava

无法在 R 中安装 rJava

我无法在 R 中安装 rJava 包。

如果我运行sudo R CMD javareconf

*** JAVA_HOME is not a valid path, ignoring
Java interpreter : /usr/bin/java
Java version     : 1.8.0_161
Java home path   : /usr/lib/jvm/java-8-oracle/jre
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
trying to compile and link a JNI program 
detected JNI cpp flags    : -I$(JAVA_HOME)/../include - 
I$(JAVA_HOME)/../include/linux
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/lib/jvm/java-8- 
oracle/jre/../include -I/usr/lib/jvm/java-8- 
oracle/jre/../include/linux     
-fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat - 
Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c conftest.c -o 
conftest.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o 
conftest.so conftest.o -L/usr/lib/jvm/java-8- 
oracle/jre/lib/amd64/server -ljvm -L/usr/lib/R/lib -lR

JAVA_HOME        : /usr/lib/jvm/java-8-oracle/jre
Java library path: $(JAVA_HOME)/lib/amd64/server
JNI cpp flags    : -I$(JAVA_HOME)/../include - 
I$(JAVA_HOME)/../include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
Updating Java configuration in /usr/lib/R
Done.

我还运行了以下命令:

export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export PATH=$PATH:$JAVA_HOME/bin

但我真的不知道它应该做什么......

最后必须提到的是

  • 如果我安装并运行rJava(使用库(rJava))在 sudo 模式下一切正常。

  • 如果我在正常用户模式下运行 rJava

    library(rJava)
    

    我收到以下错误:

    library(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 '/home/marc/R/x86_64-pc-linux- 
    gnu-library/3.4/rJava/libs/rJava.so':
    libjvm.so: cannot open shared object file: No such file or directory
    
  • 如果我尝试在普通用户模式下安装 rJava,在测试包是否可以加载时我会得到与之前相同的错误:

    ** testing if installed package can be loaded
    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 '/home/marc/R/x86_64-pc-linux- 
    gnu-library/3.4/rJava/libs/rJava.so':
    libjvm.so: cannot open shared object file: No such file or directory
    Error: loading failed
    Execution halted
    

欢迎任何帮助。

答案1

尝试:

更新替代方案——配置 java

这给出了如下输出:

  • 2 /usr/lib/jvm/java-8-oracle/jre/bin/java

添加到您的 /etc/environment

JAVA_HOME='/usr/lib/jvm/java-8-oracle'

然后删除并重新安装 r-base:

sudo apt-get 删除 r-base

sudo apt-get 安装 r-base

现在尝试再次安装 rJava。

相关内容