问题
Trying to install the rJava package on R, on my 14.10 ubuntu, using this code
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
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
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
回答1:
I was getting the same error when I was trying to load rJava in RStudio. The following solution worked for me
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
> library("DBI")
> library("rJava")
> library("RJDBC")
回答2:
To solve this,
- Run
sudo R CMD javareconf
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)
- Run the following:
source /etc/environment
- rstudio server restart
回答3:
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
回答4:
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
rJava
compiling it from the source code.
回答5:
If someone is coming here now, Please try the approach below:
Steps:
Find your R location. It will be stored in
rsession-ld-library-path
inrserver.conf
file. Or just by doingwhich R
. The location usually is/usr/lib64/R/lib
or/usr/lib64/microsoft-r/3.3/lib64/R/lib
Find the
libjvm.so
file which is usually in theusr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server
path depending on which jre you're using. Check in $JAVA_HOME environment.Create a symlink using
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
Restart R server
回答6:
Check if $JAVA_HOME
points to the correct location by
echo $JAVA_HOME
I am using openjdk, however $JAVA_HOME
was pointing to some non-existing oracle-java folder.
After fixing $JAVA_HOME
run
sudo R CMD javareconf
Check the output. Java headers gen.
should point to /usr/bin/javah
. For example:
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 rJava
package.
回答7:
Well, as @user3673 has pointed out this, the solution for me was change the following line in /usr/lib/R/etc/ldpaths
:
: ${R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/lib/amd64/server}
by this one:
: ${R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/jre/lib/amd64/server}
回答8:
We are using AZUL. I could see ZST is not added properly. After adding ZST, it works fine.
来源:https://stackoverflow.com/questions/28462302/libjvm-so-cannot-open-shared-object-file-no-such-file-or-directory