Where does rJava takes location of JDK from? - r

Where does rJava take location of JDK from ? I have JAVA_HOME set but on install.packages("rJava") I get this
checking Java support in R... present:
interpreter : '/usr/lib/jvm/default-java/jre/bin/java'
archiver : '/usr/lib/jvm/default-java/bin/jar'
compiler : '/usr/lib/jvm/default-java/bin/javac'
header prep.: '/usr/lib/jvm/default-java/bin/javah'
cpp flags : '-I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux'
java libs : '-L/usr/lib/jvm/default-java/jre/lib/amd64/server -ljvm'
checking whether Java run-time works...
./configure: line 3736: /usr/lib/jvm/default-java/jre/bin/java: No such file or directory
no
configure: error: Java interpreter '/usr/lib/jvm/default-java/jre/bin/java' does not work
ERROR: configuration failed for package ‘rJava’
I can't figure out where it takes /usr/lib/jvm/default-java/ from.

From R which stores this when it is configured:
edd#max:~$ grep ^JAVA /etc/R/Makeconf
JAVA = /usr/lib/jvm/default-java/jre/bin/java
JAVAC = /usr/lib/jvm/default-java/bin/javac
JAVAH = /usr/lib/jvm/default-java/bin/javah
JAVA_HOME = /usr/lib/jvm/default-java
JAVA_CPPFLAGS = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
JAVA_LIBS = -L$(JAVA_HOME)/jre/lib/amd64/server -ljvm
JAVA_LD_LIBRARY_PATH = $(JAVA_HOME)/jre/lib/amd64/server
edd#max:~$
If you update your Java toolchain you can update this via R CMD javareconf.

Related

Problems installing R packages-C compilers on macOS Catalina 10.15.4

I am having issues installing R packages in a conda environment on MacOS 10.15.4. The command install.packages() in R leads to the following type of errors (I am not pasting the full log):
ld: symbol(s) not found for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
Error 1
ERROR: compilation failed for package ‘xml2’
checking for gcc... x86_64-apple-darwin13.4.0-clang
checking whether the C compiler works... no
configure: error: in `/private/var/folders/k6/p2cdz1dx32g3p4hmwghns3fc0000gn/T/RtmpdPz2VA/R.INSTALL4817a82715f/uuid':
configure: error: C compiler cannot create executables
I am using r version 3.6.1 on a platform x86_64-apple-darwin13.4.0
The clang version is:
clang version 4.0.1 (tags/RELEASE_401/final)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /opt/anaconda3/envs/r_omics/bin
So I assumed there was an issue/conflict with the way the C compilers on my computer process R-packages installation but I don't know how to solve this.
Somehow I manage to install some of the packages through conda install but I don't manage through this to recover the environment I need.
Thank you very much for your help

rJava linker error licuuc with Anaconda & fopenmp error without Anaconda for macOS Sierra 10.12.4

I want to install rJava on macOS Sierra 10.12.4. My current Java version is Java version: 1.8.0_131, according to R CMD javareconf|grep version. I have installed Java with Homebrew's cask.
My Java runs the following
$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
My R version is
R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin11.4.2 (64-bit)
R Java config runs such that
$ R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.8.0_131
Java home path : /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
Non-system Java on macOS
trying to compile and link a JNI program
detected JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
During startup - Warning messages:
1: Setting LC_COLLATE failed, using "C"
2: Setting LC_TIME failed, using "C"
3: Setting LC_MESSAGES failed, using "C"
4: Setting LC_MONETARY failed, using "C"
clang -I/Volumes/osx/201705_anaconda/anaconda/lib/R/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include/darwin -I/Volumes/osx/201705_anaconda/anaconda/include -fPIC -I/Volumes/osx/201705_anaconda/anaconda/include -c conftest.c -o conftest.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Volumes/osx/201705_anaconda/anaconda/lib/R/lib -arch x86_64 -L/Volumes/osx/201705_anaconda/anaconda/lib -lgfortran -L/Volumes/osx/201705_anaconda/anaconda -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server -ljvm -L/Volumes/osx/201705_anaconda/anaconda/lib/R/lib -lR -lintl -liconv -lc -Wl,-framework -Wl,CoreFoundation
JAVA_HOME : /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /Volumes/osx/201705_anaconda/anaconda/lib/R
Done.
which looks to be properly set-up as guided here and this SO thread unable to compile JNI program rJava so the JDK looks to be correctly installed.
I get the linker error with the command install.packages("rJava")
checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver : '/usr/bin/jar'
compiler : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags : '-I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/../include/darwin'
java libs : '-L/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/server -ljvm'
...
ld: library not found for -licuuc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
I have got the same error despite Java sources: official JDK and Homebrew's Java return the same linker/library error.
What could be causing this linker/library licuuc error with Anaconda and how to fix it?
Old threads
Install rJava on macOS Sierra 10.12.1: linker error licuuc: a solution candidate with MacPorts
rJava on MacOS Sierra 10.12.15: unsupported option fopenmp
rJava load error in RStudio/R after "upgrading" to OSX Yosemite
Install xlsx and rJava on macOS Mavericks 10.9.5
Fixes that I have tried
options("java.home") returns NULL so options("java.home"="/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/") as guided by here
Unistalled Homebrew's Java and replaced it with Oracele's Java and JDK here: the same licuuc library/linker error persists. I tried sudo Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")' guided by this but the same licuuc library not found error.
Updated macOS from El Capitan 10.11.6 to Sierra 10.12.4 but the same licuuc library/linker error persists.
Running without sudo, javac missing (following this here and this here). This error may be easiest to fix with pointing the javac directory there to /usr/bin/javac but better solution? When I run it with sudo, I got the same licuuc error.
R CMD javareconf -e LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_LD_LIBRARY_PATH
Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")'
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/javac"
(-1)
make[2]: *** [org/rosuda/JRI/Rengine.class] Error 2
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
After removal of Anaconda conda install anaconda-clean; anaconda-clean --yes; rm -rf ~/anaconda, guided here, and installing R with cask such that brew cask install r-app; sudo R CMD javareconf; Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")' so getting a new error
clang: error: unsupported option '-fopenmp'
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
What could be causing this error forenmp without Anaconda and how to fix it?
I provide the solution in two ways: Anaconda and the Brew way. I suggest you to use the Brew solution. In both cases, I have Oracle's JDK installed and if you do this, remember reconfigure Java for R with sudo R CMD javareconf.
Anaconda (solution to the licuuc error)
A similar linker error occurred here. The anaconda path messes things up as
$ R CMD config --ldflags
-L/Users/osx/anaconda3/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lm -liconv -licuuc -licui18n
so remove a path like below from ~/.bash_profile
export PATH="/Users/osx/anaconda3/bin:$PATH" #Removed to install rJava
so we should get something like
$ R CMD config --ldflags
-F/Library/Frameworks/R.framework/.. -framework R -lpcre -llzma -lbz2 -lz -licucore -lm -liconv
and after this rJava can be installed even with Anaconda with
sudo R CMD javareconf
Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")'
congratulations!
Brew (solution to fopenmp error)
Your R installation should be done with Homebrew cask such that
brew cask install r-app
where brew's r package is not enough for this. Shortly, the forenmp problem is in the compiler not having the flag so we have to recompile the compiler. This solution is explained more thoroughly here. The problem in the question is for 3.3.* R and gcc solution used such that
#xcode-select --install #if Xcode commandline tools not installed
brew install homebrew/versions/gcc49 --without-multilib #Long ~70min compiling...
sudo chown -R $(whoami):admin /usr/local
brew link --overwrite --force gcc49
brew unlink gcc49 && brew link gcc49
brew install llvm
mkdir ~/.R; touch ~/.R/Makevars
echo "VER=-4.9
CC=gcc$(VER)
CXX=g++$(VER)
CXX1X=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc/4.9.3/lib/gcc/4.9" > ~/.R/Makevars
and now
sudo R CMD javareconf
Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")'
and now rJava is working!
Solutions here mentioned also in the following because of similar problems
Install rJava on macOS Sierra 10.12.1: linker error licuuc
rJava on MacOS Sierra 10.12.15: unsupported option fopenmp

"Unable to compile a JNI program" when installing rJava [duplicate]

I am not able to call rJava package in R 3.0. I got the following message
Error: package ‘rJava’ was built before R 3.0.0: please re-install it
I am getting error when I tried to re-install rJava package. I have provided the output of R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.7.0_21
Java home path : /usr/lib/jvm/java-7-openjdk-i386/jre
Java compiler : /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/javac
Java headers gen.: /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/javah
Java archive tool: /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/jar
trying to compile and link a JNI progam
detected JNI cpp flags :
detected JNI linker flags :
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -O2 -pipe -g -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
compilation terminated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /usr/lib/R
Done.
I am using Ubuntu 13.04. I also tried apt-get install r-cran-rjava which is not helping to solve the issue. Regarding jni.h there were some solution here. But, not sure how can I use the solution here.
I ran into the exact same issue. My solution was to install the openjdk-7-* via
sudo apt-get install openjdk-7-*
Followed that with
sudo R CMD javareconf
and I was then able to install rJava in R via install.packages("rJava").
While perhaps not the most elegant solution it appears to have solved my problems with getting rJava to work.
For those getting the error:
error: unable to load shared object '/some/dir/rJava/libs/rJava.so': libjvm.so:
cannot open shared object file: No such file or directory
I solved the error locating the library in the system and linking them to /usr/lib:
$sudo updatedb
$locate libjvm.so
/usr/lib/debug/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/debug/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/jamvm/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
$sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib/
Installing rJava from the distribution packages as proposed in this askUbuntu answer also works:
sudo apt-get install r-cran-rjava
NOTE: tried from a Debian system.
I was also facing same error which was on RHEL8.1 & i resolved it as follows:
yum --enablerepo=* install java-1.8*
later i ran same command which was giving me error logs of R server.
R CMD javareconf
which turns into following output.

rJava installation in R on debian

After updating to R 3.0.1 on a Debian 64-bit machine, the rJava package does not want to install.
configuration failed, so sudo R CMD javareconf [this worked on another debian machine]. however it does not work here, has anybody else had this problem? [see terminal output below]
henk#crunchbang:~$ sudo R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.6.0_18
Java home path : /usr/lib/jvm/java-6-openjdk/jre
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
trying to compile and link a JNI progam
detected JNI cpp flags :
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -O3 -pipe -g -c conftest.c -o conftest.o
conftest.c:1:17: error: jni.h: No such file or directory
conftest.c: In function ‘main’:
conftest.c:4: warning: implicit declaration of function ‘JNI_CreateJavaVM’
make: *** [conftest.o] Error 1
Unable to compile a JNI program
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /usr/lib64/R
Done.
# check java
henk#crunchbang:~$ java -version
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8.13) (6b18-1.8.13-0+squeeze2)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)
java environment:
henk#crunchbang:~$ aptitude search "?provides(java-runtime)"
i A default-jre - Standard Java or Java compatible Runtime
i A default-jre-headless - Standard Java or Java compatible Runtime (headle
p gcj-4.4-jre - Java runtime environment using GIJ/classpath
p gcj-4.4-jre-headless - Java runtime environment using GIJ/classpath (he
p gcj-jre - Java runtime environment using GIJ/classpath
p gcj-jre-headless - Java runtime environment using GIJ/classpath (he
i A openjdk-6-jre - OpenJDK Java runtime, using Hotspot JIT
i A openjdk-6-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headles
i sun-java6-jre - Sun Java(TM) Runtime Environment (JRE) 6 (archit
I took these steps (on an EC2 with Ubuntu 14.04 and RStudio-Server) to install the R package qdap which requires rJava:
(I'm probably quoting other sources here and there and I don't remember from where, but thanks.)
Install these repositories from http://sites.psu.edu/theubunturblog/cran2deb4ubuntu/
(debian: http://r-forge.r-project.org/projects/cran2deb/)
sudo add-apt-repository ppa:marutter/rrutter
sudo add-apt-repository ppa:marutter/c2d4u
sudo apt-get update
Install Java:
sudo apt-get install openjdk-7-jdk
ls /usr/lib/jvm
Set a system-wide environment variable for Java:
sudo joe /etc/profile.d/javaenvvar.sh
which contains:
# JAVA environment variable
# for openjdk-7-jdk in order to use the R package `qdap`.
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
export PATH=$PATH:$JAVA_HOME/bin
Then exit BASH and sign in again. Check your path changes:
echo $PATH
echo $JAVA_HOME
Then:
sudo R CMD javareconf
Should return:
Java interpreter : /usr/bin/java
Java version : 1.7.0_65
Java home path : /usr/lib/jvm/java-7-openjdk-amd64/jre
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
Create the file /etc/ld.so.conf.d/java.conf with the following entries:
/usr/lib/jvm//usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64
/usr/lib/jvm//usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server
Then install rJava from those new repositories:
sudo apt-get install r-cran-rjava
That just installed rJava to /usr/lib/R/site-library which is accessible to all users of RStudio-Server, hopefully.
sudo update-alternatives --config java
Hopefully, there's only one java installed.
Update R packages:
sudo R
> packageStatus()
> update.packages()
Install R packages system wide (still within sudo R):
> install.packages("qdap", lib="/usr/lib/R/site-library")
Reset RStudio-Server:
Sign out of RStudio-Server first.
sudo rstudio-server stop
sudo rstudio-server start
Sign back in to RStudio-Server.
If you get a memory error, try detaching some packages.
The EC2 t2-micro has only 1 GB of RAM.
I had the same problem, the solution was updating to openjdk-7-* and use update-alternatives --config java to set the java-7-openjdk path.

rJava fails to install (MacOS, Red Hat)

I am experiencing the same rJava problem that many other people seem to of had at one point or another. The error occurs when R CMD INSTALL tests whether JNI programs can be compiled.
The output recommends running R CMD javareconf -ed or sudo R CMD javareconf The output of the latter is :
computer: home$ sudo R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.6.0_31
Java home path : /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
Java library path:
JNI linker flags : -framework JavaVM
JNI cpp flags : -I$(JAVA_HOME)/include
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.
And when trying to install rJava afterwards,
computer: home$ R CMD INSTALL ~/Downloads/rJava_0.9-4.tar.gz
* installing to library ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library’
* installing *source* package ‘rJava’ ...
checking for gcc... gcc -arch x86_64 -std=gnu99
checking for C compiler default output file name... a.out
/* Passes all checks */
configure: checking whether gcc -arch x86_64 -std=gnu99 supports static inline...yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver : '/usr/bin/jar'
compiler : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags : '-I/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include'
java libs : '-framework JavaVM'
checking whether JNI programs can be compiled... 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’
* removing ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library/rJava’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library/rJava’
An alternative attempt where /usr/bin/javac is replaced by /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Homefails just the same.
I am running Mac OS 10.7.3 and
computer: home$ java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-415-11M3646)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-415, mixed mode)
The following is in my .bash_profile
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Additionally, I have the same problem on Red-Hat. I hope any fix provided will work there too, but if it won't and why it won't is know, please explain.
I've been using this site's incredible knowledge base for a couple of years now, but this is my first post. Mucho thanks in advance.
Some (not all) of the resources I have already browsed through are
https://stat.ethz.ch/pipermail/r-devel/2008-November/051224.html
https://stat.ethz.ch/pipermail/r-help/2008-October/177688.html
R: rJava package install failing
Please note that the apt-get solution in the last link is of no use to me (I think) unless there is an equiv solution for port and/or yum.
I am using Redhat Linux 7.1
I was getting the same problem as above and I performed the following steps
1) Edit /usr/lib64/R/etc/Renviron and add "CPPFLAGS=${CPPFLAGS-'-ldl'}" to the end of the file
2) Then find the java home and set it like below ( set java home till /jre)
$export JAVA_HOME=/usr/lib/jvm/java-1.7.1-ibm-1.7.1.3.10-1jpp.1.el7_1.x86_64/jre
$export PATH=$PATH:$JAVA_HOME/bin
$R CMD javareconf
3) invoke R from commandline
$R
> install.packages("rJava")
> install.packages("RJDBC",dep=TRUE)
> q()
Save workspace image? [y/n/c]: y
I had a recent variation on this same problem with RHEL 6.5. I reviewed this thread and many others. The ptoblem was that the dynamic load modules were not found when testing the complile of the JNI programs. My fix was to insert "CPPFLAGS=${CPPFLAGS-'-ldl'}" into file
/usr/lib64/R/etc/Renviron

Resources