Recently, I have transplanted some web gadgets published by the scientific community to the server of our Shengxin Skill Tree. I found that many tools depend on the R package of rJava. In fact, it is still difficult to install on Ubuntu, so share it!
Because it's a server that is entirely my own, so I installed the latest version of R language at the time of purchase
ubuntu@VM-0-3-ubuntu:~$ which R
/usr/bin/R
ubuntu@VM-0-3-ubuntu:~$ R --version
R version 3.6.1(2019-07-05)--"Action of the Toes"Copyright(C)2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu(64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
However, for JAVA, I chose more stable java8
ubuntu@VM-0-3-ubuntu:~$ which java
/usr/bin/java
ubuntu@VM-0-3-ubuntu:~$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment(build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)
OpenJDK 64-Bit Server VM(build 25.222-b10, mixed mode)
Next, start installing rJava based on these system environments!
The code is:
options("repos"=c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
install.packages("rJava")
The first error was:
configure: error: Java Development Kit(JDK) is missing or not registered in R
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.
Now that the error log indicates that we should use root privileges, run the command: R CMD javareconf
It was found that running: R CMD javareconf
did not solve the problem, but introduced a new error:
trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags :-L$(JAVA_HOME)/lib/amd64/server -ljvm
During startup - Warning message:
Setting LC_CTYPE failed, using "C"
gcc -std=gnu99 -I"/usr/share/R/include"-DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-uuRxut/r-base-3.6.1=.-fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2-g -c conftest.c -o conftest.o
conftest.c:1:10: fatal error: jni.h: No such file or directory
# include <jni.h>^~~~~~~
compilation terminated./usr/lib/R/etc/Makeconf:167: recipe for target 'conftest.o' failed
make:***[conftest.o] Error 1
Unable to compile a JNI program
Similarly, Google search for keywords, and found a solution: https://stackoverflow.com/questions/42562160/r-cmd-javareconf-not-finding-jni-h
The problem is that I installed java jre instead of jdk, so I need to install it again:
# sudo apt install openjdk-8-jre-headless
# I installed jre before using the above code instead of jdk
sudo apt-get install openjdk-8-jdk
Then it succeeded!
Of course, on the Windows platform and the MAC platform, the solution to the problem is definitely different, but the idea of solving the problem is the same. **
**Another similar tutorial: **Why is the R image of Tsinghua Yuan missing the rvest package
Recommended Posts