Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R studio failing to use rJava lib and failing javareconf

Tags:

r

rjava

I'm running Rstudio on its own server. Java is installed with good java_home and bin. R is installed. rJava is installed.

Tried to do command: library("rJava") but had issues with libjvm.so, do following Rstudio recommandation I did sudo R CMD javareconf with root.

Here is the output of my javareconf:

Java interpreter : /home/scoremd/jdk1.7.0_03/jre/bin/java
Java version : 1.7.0_03
Java home path : /home/scoremd/jdk1.7.0_03
Java compiler : /home/scoremd/jdk1.7.0_03/bin/javac
Java headers gen.: /home/scoremd/jdk1.7.0_03/bin/javah
Java archive tool: /home/scoremd/jdk1.7.0_03/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)/jre/lib/amd64:$(JAVA_HOME)/jre/lib/amd64/server
JNI linker flags : -L$(JAVA_HOME)/jre/lib/amd64 -L$(JAVA_HOME)/jre/lib/amd64/server -ljvm
JNI cpp flags : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux

Seems there is issue with finding the java library path... but my java is working fine and R also.

I didn't receive any solution from RStudio support and community (told me to ask in SO ....).

like image 773
Vince Avatar asked Mar 19 '12 15:03

Vince


1 Answers

I have rstudio-server installed on my Centos server. There are a couple of users using rstudio and we decided to upgrade R from 3.6 to 4.0.

After the upgrade :

  • all users were running R 4.0.
  • No user could install rJava using install.package('rJava'). This error always popped up

configure: error: Cannot compile a simple JNI program. See config.log for details. Make sure you have Java Development Kit installed and correctly registered in R. If in doubt, re-run "R CMD javareconf" as root. ERROR: configuration failed for package ‘rJava’

  • Running SUDO R CMD javareconf went smoothly, and also when I opened R as root and went along and tried install.packages('rJava') it installed the package just fine. (unbeknownst to me, root ran R 3.6 and users 4.0, see solution below)
  • However it did not work installing the package for users in R studio server. Always stating the same "try running sudo R CMD javareconf" as if the Java path for the users was wrong.
  • so we tried setting the "JAVA_HOME" variable to the same path that java jdk was installed in (found by searching installed packages in yum). That did not solve it.

my solution I saw that root was running version 3.6 of R while all users ran 4.0. This was because I had installed 4.0 in another directory.. The directory of R 4.0 happens to be found first by the users. However for the root user... it finds the path of R 3.6 first. So I set the path to the 4.0 folder in the $PATH variable of the root user, so that would find version 4.0 before finding R 3.6

  • echo $PATH
  • export PATH="/usr/local/bin:$PATH"
  • echo $PATH

Then I ran R as that user and ran "R CMD javareconf", installed the packages and all users are happy and working again.

(disclaimer, I'm not a experienced linux admin, there may be a better solution for running different R versions)

like image 160
Andri Ólafsson Avatar answered Oct 22 '22 17:10

Andri Ólafsson