I've tried to solve this using the previous questions/answers on SO but without any success. So, here's my problem.
I'm using RStudio on and Ubuntu box (14.04) and I tried to upgrade rJava from sources and in the process I managed to lose it.
I tried to install it again using,
install.packages("rJava")
which returned the following error message,
configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.
If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/darren/R/x86_64-pc-linux-gnu-library/3.2/rJava’
Warning in install.packages :
installation of package ‘rJava’ had non-zero exit status
So, I went to the terminal and typed,
sudo R CMD javareconf
which also gave the following error,
trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags : -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
#include <jni.h>
^
compilation terminated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program
JAVA_HOME : /usr/lib/jvm/default-java
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /usr/lib/R
Done.
I tried to follow these links, one and two but they didn't seem to resolve my issue; there are more links on SO but I'm not sure which one to follow. I've also un-installed and re-installed RStudio via the Ubuntu Software Centre but this didn't make any difference.
Can anyone else help?
In short, I want to be able to use RStudio with rJava again without it destroying any other uses of Java (such as jmol).
First i would recommend installing Rstudio from its website: https://www.rstudio.com/products/rstudio/download/ (i.e. Rstudio 64bit: https://download1.rstudio.org/rstudio-0.99.489-amd64.deb). This does not solve the problem directly, but it helps to avoid other bugs with Rstudio.
Regarding the error, trying to make sure you have JDK install. I don't think the command
java -version
can tell if JDK is installed. You have to check the package of JDK itself, or based on the error message, do this:locate jni.h
The output should match or compatible with your JAVAHOME, e.g:Update 1:
R CMD javareconf
is looking for thejni.h
file under$(JAVA_HOME)/include
You have JDK installed, but it is very likely that you are having default java to a JRE directory, that why the error happened.You can see where
default-java
is really pointing to by doing this command:If the
ls
command failed, you have to setup so thatjavareconf
( and laterrJava
) can use the java from JDK not from JRE. You have two options:Method 1: Do it system-wide
This is convenient, but may effect other program like the one you mentioned
jmol
. But don't worry, this is revertible, just re-run the command and pick the old one. Do the following command and pick the dir that has JDK:After that test how
jmol
works, if it works alright then congrat. You are now ready to test rJava. If not, try the second method belowMethod 2: Do it for R only
put this in the
.Rprofile
under your home directoryAfter updating or creating the
.Rprofile
DO restart R in Rstudio. TheR CMD javareconf
may still fail in this case, but it should be OK if you run it fromShell
underTools
menu of Rstudio.Regarding the installing or Rstudio from Ubuntu's stock repo. It would not make a difference for getting
rJava
running. Then again, I recommend installing Rstudio for its homepage because new version also has some nice features (i.e. better autocompletion, which I like the most).You don't seem to have JDK installed. You will need at least
then re-run
Make sure you do NOT set
JAVA_HOME
by hand - it will be detected automatically. You should then see something like this:I've been dealing with this exact issue, nothing in this thread or other that are similar have solved it. I'm on Ubuntu 16.04, here's how I got it to work:
apt-get install openjdk-9-jdk rm -rf /usr/lib/jvm/default-java ln -s /usr/lib/jvm/java-9-openjdk-amd64/ /usr/lib/jvm/default-java
What is wrong with
sudo apt-get install r-cran-rjava
?See for example this earlier answer and the question / thread around it.
For an installation from scratch, you could still much worse than starting from
sudo apt-get build-dep r-cran-rjava
. It will get you the JDK corresponding to your Ubuntu version.You can see where the
JAVA_HOME
is in the error message.Then use
locate jni.h
to find where isjni.h
, next use soft link to link this location to$(JAVA_HOME)/include
, just like @biocyberman mentioned.This is what I did:
Since my
JAVA_HOME
is/opt/conda
and I also don't havejni_md.h
and-ljvm
.I am use Ubuntu
16.04
.