libjvm.so:无法打开共享对象文件:没有这样的文件或目录

2022-09-01 08:11:26

尝试在我的 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 

但这没有奏效,我还能做其他事情吗?我将提供任何需要的详细信息


答案 1

当我尝试在RStudio中加载rJava时,我得到了同样的错误。以下解决方案对我有用

1) sudo rstudio-server stop
2) export LD_LIBRARY_PATH=/usr/lib/jvm/jre/lib/amd64:/usr/lib/jvm/jre/lib/amd64/default
3) sudo rstudio-server start

执行上述步骤后,我能够在RStudio中成功运行以下内容

> library("DBI")
> library("rJava")
> library("RJDBC")

答案 2

为了解决这个问题,

  1. sudo R CMD javareconf

  2. 将以下内容添加到 /etc/环境中。然后,每次重新启动计算机时都会设置此项。

    LD_LIBRARY_PATH=/usr/lib/jvm/default-java/jre/lib/amd64/server/

    (更改您的路径)

  3. 运行以下命令:

    源/等/环境

  4. rstudio server reboot