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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28462302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 06:16:56  来源:igfitidea点击:

libjvm.so: cannot open shared object file: No such file or directory

javarubunturjavaubuntu-14.10

提问by tan

Trying to install the rJava package on R, on my 14.10 ubuntu, using this code

尝试使用此代码在我的 14.10 ubuntu 上的 R 上安装 rJava 包

if (!require(rJava)) install.packages('rJava')

got few errors related to java including jni problems, after reinstalling the jdk, and tried to run the same code again, got that error

在重新安装 jdk 后,遇到了一些与 java 相关的错误,包括 jni 问题,并尝试再次运行相同的代码,得到了那个错误

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'

looked for solutions, to find just about everyone suggesting (for x64) to execute those commands

寻找解决方案,找到几乎所有建议(对于 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 

but that didn't work, is there anything else I can do? I will provide any needed details

但这不起作用,我还能做些什么吗?我会提供任何需要的细节

回答by Francesco Palmiotto

  • I solved a similar issue by running the following command every time I want to open RStudio. Go to the folder which contains the rstudio executable, open up the terminal and type:

    LD_LIBRARY_PATH=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/server: open -a rstudio

    Of course you have to change the path according to your Java version.

  • If the previous solution does not work, try reading this article: http://allanino.me/blog/programming/installing-some-r-packages/.

  • If this solution does not work too, the last chance you have is to install rJavacompiling it from the source code.

  • 每次我想打开 RStudio 时,我都通过运行以下命令解决了类似的问题。转到包含 rstudio 可执行文件的文件夹,打开终端并键入:

    LD_LIBRARY_PATH=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/server: open -a rstudio

    当然,您必须根据您的 Java 版本更改路径。

  • 如果之前的解决方案不起作用,请尝试阅读这篇文章:http: //allanino.me/blog/programming/installing-some-r-packages/

  • 如果此解决方案也不起作用,那么您最后的机会是安装rJava从源代码编译它。

回答by minhas23

I was getting the same error when I was trying to load rJava in RStudio. The following solution worked for me

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

After performing the above steps, I was able to run the following successfuly in RStudio

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

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

回答by Haktan Suren

in case none of the above works, try this and thank me later (generic answer) :)

如果上述方法均无效,请尝试此操作并稍后感谢我(通用答案):)

R CMD javareconf -e
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_LD_LIBRARY_PATH

回答by aGentlemanAndAScholar

To solve this,

为了解决这个问题,

  1. Run

    sudo R CMD javareconf

  2. Add the following to to /etc/environment. This will then be set every time your machine restarts.

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

    (change to your path)

  3. Run the following:

    source /etc/environment

  4. rstudio server restart
  1. 须藤 R CMD javareconf

  2. 将以下内容添加到 /etc/environment. 这将在您的机器每次重新启动时设置。

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

    (更改为您的路径)

  3. 运行以下命令:

    源 /etc/environment

  4. rstudio 服务器重启

回答by Tejas Lodaya

If someone is coming here now, Please try the approach below:

如果有人现在来这里,请尝试以下方法:

Steps:

脚步:

  1. Find your R location. It will be stored in rsession-ld-library-pathin rserver.conffile. Or just by doing which R. The location usually is /usr/lib64/R/libor /usr/lib64/microsoft-r/3.3/lib64/R/lib

  2. Find the libjvm.sofile which is usually in the usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/serverpath depending on which jre you're using. Check in $JAVA_HOME environment.

  3. Create a symlink using ln -ssudo 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

  4. Restart R server

  1. 找到您的 R 位置。它将存储rsession-ld-library-pathrserver.conf文件中。或者只是通过做which R。位置通常是/usr/lib64/R/lib/usr/lib64/microsoft-r/3.3/lib64/R/lib

  2. 根据您使用的 jre查找libjvm.so通常位于usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server路径中的文件。签入 $JAVA_HOME 环境。

  3. 使用创建符号链接 ln -ssudo 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

  4. 重启 R 服务器

回答by Fábio

Well, as @user3673has pointed out this, the solution for me was change the following line in /usr/lib/R/etc/ldpaths:

那么,作为@ user3673指出这个,对我来说,解决办法是更改以下行/usr/lib/R/etc/ldpaths

: ${R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/lib/amd64/server}

: ${R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/lib/amd64/server}

by this one:

通过这个:

: ${R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/jre/lib/amd64/server}

: ${R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/jre/lib/amd64/server}

回答by djhurio

Check if $JAVA_HOMEpoints to the correct location by

检查是否$JAVA_HOME指向正确的位置

echo $JAVA_HOME

I am using openjdk, however $JAVA_HOMEwas pointing to some non-existing oracle-java folder.

我正在使用 openjdk,但是$JAVA_HOME指向了一些不存在的 oracle-java 文件夹。

After fixing $JAVA_HOMErun

修复后$JAVA_HOME运行

sudo R CMD javareconf

Check the output. Java headers gen.should point to /usr/bin/javah. For example:

检查输出。Java headers gen.应该指向/usr/bin/javah. 例如:

djhurio@Skyforger ~ $ sudo R CMD javareconf
Java interpreter : /usr/lib/jvm/default-java/bin/java
Java version     : 11.0.1
Java home path   : /usr/lib/jvm/default-java
Java compiler    : /usr/lib/jvm/default-java/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/lib/jvm/default-java/bin/jar

After this I can install and load rJavapackage.

在此之后,我可以安装和加载rJava包。

回答by Rohit

We are using AZUL. I could see ZST is not added properly. After adding ZST, it works fine.

我们正在使用 AZUL。我可以看到 ZST 没有正确添加。添加ZST后,它工作正常。