尝试在我的 14.10 ubuntu 上使用此代码在 R 上安装 rJava 包
if (!require(rJava)) install.packages('rJava')
出现了一些与 java 相关的错误,包括 jni 问题,重新安装 jdk 后,尝试再次运行相同的代码,出现了该错误
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/usr/local/lib/R/site-library/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/site-library/rJava’
Warning in install.packages :
installation of package ‘rJava’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpfFjrp0/downloaded_packages’
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘rJava’
寻找解决方案,发现几乎每个人都建议(对于 x64)执行这些命令
export LD_LIBRARY_PATH=/usr/lib/jvm/java-8-oracle/lib/amd64:/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server
sudo R CMD javareconf
但那没用,我还能做什么?我会提供任何需要的详细信息,在整个机器上搜索 libjvm.so 会导致此结果
/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server/libjvm.so
/usr/lib/jvm/jdk1.8.25/jre/lib/amd64/server/libjvm.so
/usr/local/java/jre1.7.0_75/lib/amd64/server/libjvm.so
答案1
执行以下操作应该可以解决您的问题:
$ export LD_LIBRARY_PATH=/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server
$ sudo R CMD javareconf
答案2
有时你需要这个R CMD javareconf -e
答案3
脚步:
找到您的 R 位置。它将存储在文件
rsession-ld-library-path
中rserver.conf
。或者只需执行which R
。位置通常是/usr/lib64/R/lib
或/usr/lib64/microsoft-r/3.3/lib64/R/lib
查找
libjvm.so
文件,该文件通常位于usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server
路径中,具体取决于您使用的 jre。检查echo $JAVA_HOME
。使用创建符号链接
ln -s
sudo ln -s /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib64/microsoft-r/3.3/lib64/R/lib/libjvm.so
重启 R 服务器