Install rJava on Ubuntu18

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!

First check the R and java versions of Ubuntu###

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 first installation of the rJava package must report an error

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

First debugging failed###

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

Install rJava on Ubuntu18
install vscode on ubuntu18
Install Redis on Ubuntu
Install R4 on ubuntu20
Install postgresql-10 on Ubuntu 18.04
Install docker on Ubuntu
Install Docker on ubuntu18.04
Install nodejs10 on Ubuntu16
Install mysql on Ubuntu 14.04
Install Django on ubuntu
Install Python3 on Ubuntu 14.04
Install JDK10+ on Ubuntu
Install Python3 on Ubuntu 16.04
Install KDE on Ubuntu16.04.2
Install Docker on Ubuntu18
Install Python3.7 on Ubuntu
Install flashplayer on Ubuntu
Docker practice (1): install Docker on Ubuntu 16.04
Install ubuntu on virtual machine
Install OpenSSL 1.0.2 on Ubuntu Server 14.04
Install Python 3.7 on Ubuntu 18.04 LTS
Install Android Studio on Ubuntu
Install scrapy framework on ubuntu
Install Mysql offline on Ubuntu
Install Oracle Java8 on Ubuntu
Install Odoo 11 stack on Ubuntu 16.04
Install Go locale on Ubuntu16
Install common software on Ubuntu 16.04
Install non-portable QQ on ubuntu
Install Docker on Ubuntu 18.04 offline
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
Install Tenda u12 driver on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
Install Chef server workstation on Ubuntu 18.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
Install botan2 encryption library on ubuntu
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
Docker ubuntu: install python-PIL-image environment on 14.04
How to install Go on Ubuntu 20.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04