error: unable to load installed packages just now
Asked Answered
C

11

41

When I tried to run the R console in Eclipse, I got this error:

....Please make sure that R package 'rj' (1.1 or compatible) is installed...

So I tried to install it in the R console like this:

install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-1.1")

and got this error:

 ** testing if installed package can be loaded
 Error : .onLoad failed in loadNamespace() for 'rj.gd', details:
 call: dyn.load(file, DLLpath = DLLpath, ...)
 error: unable to load shared object '/home/alex/R/x86_64-pc-linux-gnu-library/2.15/rj.gd/libs/rj.gd.so':
 libjvm.so: cannot open shared object file: No such file or directory
 Error: loading failed
 Execution halted
 ERROR: loading failed

and I found that when installing rJava using: install.packages("rJava") gets a similar error:

** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/alex/R/x86_64-pc-linux-gnu-library/2.15/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed

When I run sudo R CMD javareconf,I got this output:

Java interpreter : /usr/bin/java
Java version     : 1.7.0
Java home path   : /usr/lib/jvm/java-7-oracle/jre
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
NOTE: Your JVM has a bogus java.library.path system property!
Trying a heuristic via sun.boot.library.path to find jvm library...
Java library path: $(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/lib/amd64/server
JNI linker flags : -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/lib/amd64/server -ljvm
JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux

Updating Java configuration in /etc/R
Done.

by the way,my configuration is:

Ubuntu 11.10 64bit
Eclipse 3.7
Oracle-1.7-jdk
R version 2.15.1 
Cockney answered 13/10, 2012 at 11:33 Comment(0)
C
21

I found the solution:

export LD_LIBRARY_PATH=/usr/lib/jvm/java-7-oracle/lib/amd64:/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server

then

sudo R CMD javareconf

Note: The path (java-7-oracle) needs to be updated based on your Java installation.

Cockney answered 15/10, 2012 at 2:18 Comment(0)
T
80

For Linux(Ubuntu) users: If you have oracle-java (7/8) installed. It'll be at this location /usr/lib/jvm and sudo access is required.

Create the file /etc/ld.so.conf.d/java.conf with the following entries:

/usr/lib/jvm/java-8-oracle/jre/lib/amd64
/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server

(Replace java-8-oracle with java-7-oracle depending on your java version)

Then:

sudo ldconfig

Restart RStudio and then install the rJava package.

OR

Also an alternative method is to export LD_LIBRARY_PATH with the value of Java library path obtained from the command R CMD javareconf -e and run install.packages

Teresetereshkova answered 19/9, 2014 at 11:25 Comment(5)
Great work! Could you please explain what have you done? It is not clear for me (but I'm very happy because it worked!). Thank you very much!Lacuna
ldconfig is a command which will configure dynamic linker run-time bindings. It creates and updates the necessary links and cache for use by the run-time linker.Teresetereshkova
for some reason running ldconfig told me my /usr/lib/libjvm.so was 'empty'. I fixed this by sudo ln -s /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so (you should use your own java version)Hilaryhilbert
@ThomasLuechtefeld : Yeah thats true. You have to modify it as mentioned in the answer "depending on your java version". Thanks for mentioning command in comment.Teresetereshkova
Worked great for me! Thx!Magnesia
J
31

I got similar issue and was able to resolve it by running

R CMD javareconf -e

Output of the R CMD javareconf -e

Java interpreter : /export/apps/jdk/JDK-1_6_0_27/jre/bin/java
Java version     : 1.6.0_27
Java home path   : /export/apps/jdk/JDK-1_6_0_27
Java compiler    : /export/apps/jdk/JDK-1_6_0_27/bin/javac
Java headers gen.: /export/apps/jdk/JDK-1_6_0_27/bin/javah
Java archive tool: /export/apps/jdk/JDK-1_6_0_27/bin/jar
Java library path: /export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64/server:/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64:/export/apps/jdk/JDK-1_6_0_27/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
JNI linker flags : -L/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64/server -L/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64 -L/export/apps/jdk/JDK-1_6_0_27/jre/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm
JNI cpp flags    : -I/export/apps/jdk/JDK-1_6_0_27/include -I/export/apps/jdk/JDK-1_6_0_27/include/linux

The following Java variables have been exported:
JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH
Running: /bin/bash

After setting LD_LIBRARY_PATH to the same value as JAVA_LD_LIBRARY_PATH as shown in the output above. I was able to install rj.

export LD_LIBRARY_PATH=/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64/server:/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64:/export/apps/jdk/JDK-1_6_0_27/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

Run R and then install rj by

install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-1.1")
Jezreel answered 19/11, 2012 at 0:10 Comment(2)
If you using RStudio, you may also have to restart it by service rstudio-server restartMalawi
Just type export in the command line. After following what @Jezreel has mentioned, you may see that LD_LIBRARY_PATH has got updatedCotoneaster
C
21

I found the solution:

export LD_LIBRARY_PATH=/usr/lib/jvm/java-7-oracle/lib/amd64:/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server

then

sudo R CMD javareconf

Note: The path (java-7-oracle) needs to be updated based on your Java installation.

Cockney answered 15/10, 2012 at 2:18 Comment(0)
P
10

I did the following and it worked for me:

export LD_LIBRARY_PATH=$JAVA_LD_LIBRARY_PATH
sudo R CMD javareconf

I had to restart R then as well.

Plaudit answered 26/9, 2015 at 7:21 Comment(1)
I wasted a lot of time, until I found your answer, the key was to run the second command as root.Spec
P
3

Years later, I ended up on this question after searching for an error reported by R after I had unsuccessfully installed a package on that required shifting to Oracle's Java.

All I had to do to fix it was:

$ sudo R CMD javareconf

Pyrogenic answered 11/6, 2017 at 21:11 Comment(3)
I spoke too soon. The problem arose again and running javareconf again didn't fix it this time. Moreover, running sudo R to install.packages("rJava") didn't fix it either.Pyrogenic
+1 this command seemed to fix some env parameters but still stuck in trying to install rJava, any ideas for this here?Complice
Can someone explain in some detail what does R CMD javareconf do?Sherrilsherrill
M
2

or just set the library in R?

I just ran this command in R:

Sys.setenv(JAVA_HOME='/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server')

(replace "/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server" with your Java library path which can be found running "sudo R CMD javareconf")

Might not be the most elegant solution - but it worked for me!

Mcadoo answered 24/3, 2015 at 12:12 Comment(0)
D
1

I did not had the jdk installed which I could fix with sudo apt-get install jdk-* After that i could run the sudo R CMD javareconf which always drew an error message before. Everything was set correctly and no manual tweeks where required, and after that package installation ran smootly in R (restart required).

Dora answered 7/2, 2017 at 9:19 Comment(0)
C
0

When facing missing limjvm.so errors make sure that the correct ldpaths is picked up from the standard configuration in /etc/R versus the one in /usr/lib/R/etc.

Copulation answered 21/11, 2013 at 8:50 Comment(0)
P
0

This fixes the LD_LIBRARY_PATH problem for me (Linux, Debian 7.1.0, tc-shell, R version 3.0.2):

Add this line to .cshrc:

setenv LD_LIBRARY_PATH $JAVA_HOME/jre/lib/amd64:$JAVA_HOME/jre/lib/amd64/server

Adding this command to ~/.login was not enough; the environment variable LD_LIBRARY_PATH was still not known in new xterms: echo $LD_LIBRARY_PATH : LD_LIBRARY_PATH: Undefined variable. (Why??)

Curiously, when starting R as superuser, there was no problem with finding libjvm.so .

Polydipsia answered 24/2, 2014 at 10:14 Comment(0)
S
0

I fixed this by just running R with sudo, and then running install.packages('rJava`).

Silber answered 7/4, 2017 at 15:16 Comment(0)
A
0

None of the above worked for me, the only solution that installed rJava on Linux Ubuntu without any problems was to pass RScript command after installation of the base R:

$ sudo Rscript -e 'install.packages("rJava", repos = "http://cran.r-project.org/")'
Anole answered 18/4, 2017 at 19:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.