1
votes

I am trying to install the 'rJava' package in my RStudio docker image using my Dockerfile:

FROM rocker/tidyverse:3.6.1

RUN mkdir -p /rstudio
RUN mkdir -p /rscripts

RUN apt-get update && \
    apt-get install -y openjdk-11-jdk && \
    apt-get install -y liblzma-dev && \
    apt-get install -y libbz2-dev

RUN R -e "install.packages(c('rJava','mailR'))"

Following this SO post I added the above part with the apt-get commands but still I get the same error:

java libs : '-L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm' checking whether Java run-time works... ./configure: line 3766: /usr/bin/java: No such file or directory no configure: error: Java interpreter '/usr/bin/java' does not work ERROR: configuration failed for package ‘rJava’

So there is a missing file or directory but I don't know what changes I should make.

[EDIT 1]:

So, following Dirk's suggestion, I entered in the rstudio container and ran apt-get install r-cran-rjava which seems to work.
But when I install rJava package I get a new error:

error: Cannot compile a simple JNI program. Make sure you have Java Development Kit installed and correctly registered in R. If in doubt, re-run "R CMD javareconf" as root.

I tried to enter again in the container and run R CMD javareconf but that did not change the error. I also tried the following commands found on this article:

sudo apt-get install default-jre
sudo apt-get install default-jdk

But I still get:

Cannot compile a simple JNI program.

3

3 Answers

0
votes

This is a duplicate of similar answers I have already given in the Debian / Ubuntu context. The fact that you are using Docker does not matter: you should still simply install the binary!

edd@rob:~$ docker run --rm -ti r-base bash
root@ef4bb9726a21:/# apt update -qq
73 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@ef4bb9726a21:/# apt install --no-install-recommends -y r-cran-rjava                                  
Reading package lists... Done                                                                            
Building dependency tree                                                                                 
Reading state information... Done                                                                        
The following additional packages will be installed:                                          
  ca-certificates-java default-jre default-jre-headless java-common libasound2 libasound2-data libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libdbus-1-3 libdrm-amdgpu1 libdrm-common
  libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2 libedit2 libgif7 libgl1 libgl1-mesa-dri libglapi-mesa libglvnd0 libglx-mesa0 libglx0 liblcms2-2 libllvm10 libnspr4 libnss3 libpciaccess0 libpcsclite1
  libsensors-config libsensors5 libsqlite3-0 libvulkan1 libx11-xcb1 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-sync1 libxdamage1 libxfixes3 libxi6 libxshmfence1 libxtst6 libxxf86vm1 libz3-4
  openjdk-11-jre openjdk-11-jre-headless                                                                 
[.... many lines skipped ....]
Running hooks in /etc/ca-certificates/update.d...

done.
done.
root@ef4bb9726a21:/# R

R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
[...some lines skipped...]
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(rJava)
> 
0
votes

I found a github repo suggesting to add these steps in the Dockerfile before installing R package rJava and it worked:

RUN apt-get -y update && apt-get install -y \
   default-jdk \
   r-cran-rjava \
   && apt-get clean \
   && rm -rf /var/lib/apt/lists/
0
votes

The reason why Dirk's answer doesn't work for you is because you're using rocker/tidyverse as a base image instead of the r-base that Dirk is using.

In the rocker/tidyverse documentation on Docker Hub they are discouraging the use of apt install --no-install-recommends -y r-cran-rjava:

do not use apt-get install r-cran-* to install R packages on this stack. The requested R version and all R packages are installed from source in the version-stable stack. Installing R packages from apt (e.g. the r-cran-* packages) will install the version of R and versions of the packages that were built for the stable debian release (e.g. debian:stretch), giving you a second version of R and different packages. Please install R packages from source using the install.packages() R function (or the install2.r script), and use apt only to install necessary system libraries (e.g. libxml2). If you would prefer to install only the latest verions of packages from pre-built binaries using apt-get, consider using the r-base stack instead.

Since rJava is supposed to be installed with apt install r-cran-rjava, but the rocker/... base images explicitly tell you not to do that, it looks like you will not be able to use rJava with any of the rocker/... base images..