RStudio Server (community) can't find libR.so even though it is in path - r

Note: I have filed this as an issue, but I'm not sure if it is really a bug or just something I need to resolve about my system configuration.
This seems to be a library that causes many people trouble with RStudio and RStudio Server. Often people can fix the problem by reinstalling the core R libraries with apt or manually copying or linking the libR.so file to a place where RStudio finds it.
In my case, I'm using a Conda instance for my R executable.
My instance was working and stopped after upgrading my ubuntu 22.04 VM. I tried some things to fix the problem but have not succeeded.
System details
RStudio Edition : Server
RStudio Version : 2022.07.2+576 (Spotted Wakerobin) for Ubuntu Bionic
OS Version : Ubuntu 22.04.1 LTS
R Version : 4.1.3 (2022-03-10) -- "One Push-Up"
Describe the problem in detail
I have a GCP VM running ubuntu 22.04 which I use for RSS.
I did a sudo apt update && sudo apt dist-upgrade and a restart. RSS stopped working. I ran sudo rstudio-server verify-installation and received
/usr/lib/rstudio-server/bin/rsession: error while loading shared libraries: libR.so: cannot open shared object file: No such file or directory
I decided to reinstall RSS using:
wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2022.07.2-576-amd64.deb
sudo gdebi rstudio-server-2022.07.2-576-amd64.deb
and did not receive any errors during installation. However I received the same error as above with verify-installation. I then tried doing conda update --all -y. This also did not fix the problem.
Here is some useful information:
(base) balter#rstudio:~$ which R
/home/balter/conda/bin/R
(base) balter#rstudio:~$ head -n3 /etc/rstudio/rserver.conf
# Server Configuration File
rsession-which-r=/home/balter/conda/bin/R
(base) balter#rstudio:~$ find . -name "libR.so"
./conda/lib/R/lib/libR.so
./conda/pkgs/r-base-4.1.3-h7880091_3/lib/R/lib/libR.so
(base) balter#rstudio:~$ sudo rstudio-server verify-installation
TTY detected. Printing informational message about logging configuration. Logging configuration loaded from '/etc/rstudio/logging.conf'. Logging to '/var/log/rstudio/rstudio-server/rserver.log'.
/usr/lib/rstudio-server/bin/rsession: error while loading shared libraries: libR.so: cannot open shared object file: No such file or directory

Related

Rstudio not starting on Ubuntu 22.04 - error while loading shared library: libcrypto.so.1.1

There's a libcrypto.so.1 in the system, I created a symlink to it as libcrypto.so.1.1, but it does not find it.
I'm launching rstudio via the binary download: https://download1.rstudio.org/desktop/bionic/amd64/rstudio-2022.02.2-485-amd64-debian.tar.gz
This fixes it (a problem with packaging in 22.04):
wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1l-1ubuntu1.3_amd64.deb
sudo dpkg -i libssl1.1_1.1.1l-1ubuntu1.3_amd64.deb

Creating a qt GUI in Noetic and issues with catkin_create_qt_pkg

I would like to create a QT GUI package in Noetic. Previously in kinetic/melodic, this could be done using the command 'catkin_create_qt_pkg ' but it's not working in Ubuntu 20.04 as I get
catkin_create_qt_pkg: command not found
Unfortunately, noetic appears to have removed the support for the qt-create and qt-build. Thus, I get 'Unable to locate package' when I try to install them using
sudo apt-get install ros-noetic-qt-build
sudo apt-get install ros-noetic-qt-create
how to create a qt-gui in ubuntu-20.04 with noetic?
System info
Ubuntu 20.04.2 LTS Kernel
5.10.0-1050-oem

rJava package don't find Java [duplicate]

When installing rJava using the install.packages("rJava") command I get the following error:
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/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include -I/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include/linux'
java libs : '-L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/amd64/server -L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/amd64 -L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm'
checking whether JNI programs can be compiled... yes
checking JNI data types... configure: error: One or more JNI types differ from the corresponding native type. You may need to use non-standard compiler flags or a different compiler in order to fix this.
ERROR: configuration failed for package ‘rJava’
I have the Java JDK installed and java -version returns the following:
$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
When Googling around for the error I see that others are having the same issue but not finding a solution other than "install the whole JDK, not just the JRE" which I have done.
The other thing I read was to run sudo R CMD javareconf which runs quite happily with no errors.
Any ideas what my problem is?
[[EDIT]]
It's been a few months since I had this problem. I had initially solved this by editing my Java paths, as illustrated in the answer I posted below. I recently ran into the same issue on a new Ubuntu install. I tried Dirk's recommendation to use apt-get to install the rJava package. It worked perfectly. What I failed to appreciate initially is that installing packages using the Ubuntu apt-get method is fundamentally different than just loading the same package using install.packages() inside of R. The Ubuntu packages solve some issues which I didn't realize or appreciate.
Wouldn't
apt-get install r-cran-rjava
have been easier? You could have asked me at useR! :)
Turns out my problem was an issue with my JAVA_HOME environment variable. Yes, shocking I know. My initial setting for PATH and JAVA_HOME looked like this:
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin
And I added /jre so it now looks like this:
export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export PATH=$PATH:$JAVA_HOME/bin
Everything in Java seemed to work fine without the /jre but rJava would not. Odd.
That is how I make it work :
In Linux (Ubuntu 16.04 and 20.04 worked confirmed)
sudo apt-get install default-jre
sudo apt-get install default-jdk
sudo R CMD javareconf
in R:
install.packages("rJava")
Thanks - your suggestion about $JAVA_HOME lead me to a similar solution:
unset JAVA_HOME
before invoking R.
I came across the same issue, and it worked after running commands below.
export JAVA_LIBS="$JAVA_LIBS -ldl"
R CMD javareconf
See details at
http://www-01.ibm.com/support/knowledgecenter/SSPT3X_3.0.0/com.ibm.swg.im.infosphere.biginsights.install.doc/doc/install_install_r.html
This worked for me on Ubuntu 12.04 and R version 3.0
cd /usr/lib/jvm/java-6-sun-1.6.0.26/include
this is the directory that has jni.h
Next create a soft link to another required header file (I'm too lazy to find out how to include more than one directory in the JAVA_CPPFLAGS option below):
sudo ln -s linux/jni_md.h .
Finally
sudo R CMD javareconf JAVA_CPPFLAGS=-I/usr/lib/jvm/java-6-sun-1.6.0.26/include
below is one of my answers on another post - error: unable to load installed packages just now
(this is also relevant to this question)
For Linux(Ubuntu) users: If you have oracle-java (7/8) installed. It'll be at this location /usr/lib/jvm and sudo access is required.
Create the file /etc/ld.so.conf.d/java.conf with the following entries:
/usr/lib/jvm/java-8-oracle/jre/lib/amd64
/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server
(Replace java-8-oracle with java-7-oracle depending on your java version)
Then:
sudo ldconfig
Restart RStudio and then install the rJava package.
Running R under Gentoo on an AMD64. I upgraded to R 2.12.0
R version 2.12.0 (2010-10-15)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)
and those pesky messages went away.
Jan Vandermeer
I tried to install openjdk-7-* but still I had problems installing rJava. Turns out after I restarted my computer, then there was no problem at all.
so
sudo apt-get install openjdk-7-*
RESTART after installing java, then try to install package "rJava" in R
The rJava package looks for the /usr/lib/jvm/default-java/ folder. But it's not available as default. This folder have a symlink for the default java configured for the system.
To activate the default java install the following packages:
sudo apt-get install default-jre default-jre-headless
Tested on ubuntu 17.04 with CRAN R 3.4.1
What worked for me was changing JAVA_HOME from file /usr/lib/R/etc/javaconf
I first checked what was my version of Java enabled : sudo update-alternatives --config java.
In my case, it was java-8-oracle
I opened the file /usr/lib/R/etc/javaconf and replaced default-java by java-8-oracle :
${JAVA_HOME=/usr/lib/jvm/default-java}
replaced by :
${JAVA_HOME=/usr/lib/jvm/java-8-oracle}
And then sudo R CMD javareconf
I restarted RStudio, and could then install rJava.
what I do is here:
in /etc/apt/sources.list, add:
deb http://ftp.de.debian.org/debian sid main
Note:the rjava should be latest version
2 run:
sudo apt-get update
sudo apt-get install r-cran-rjava
Once update the old version of rjava, then can install rhdfs_1.0.8.
I got it working by downloading : https://cran.r-project.org/src/contrib/rJava_0.9-8.tar.gz and running command R CMD install rJava_0.9-8.tar.gz
I was facing the same problem while using Windows 10. I have solved the problem using the following procedure
Download Java from https://java.com/en/download/windows-64bit.jsp for 64-bit windows\Install it
Download Java development kit from https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html for 64-bit windows\Install it
Then right click on “This PC” icon in desktop\Properties\Advanced system settings\Advanced\Environment Variables\Under System variables select Path\Click Edit\Click on New\Copy and paste paths “C:\Program Files\Java\jdk1.8.0_201\bin” and “C:\Program Files\Java\jre1.8.0_201\bin” (without quote) \OK\OK\OK
Note: jdk1.8.0_201 and jre1.8.0_201 will be changed depending on the version of Java development kit and Java
In Environment Variables window go to User variables for User\Click on New\Put Variable name as “JAVA_HOME” and Variable value as “C:\Program Files\Java\jdk1.8.0_201\bin”\Press OK
To check the installation, open CMD\Type javac\Press Enter and
Type java\press enter
It will show
In RStudio run
Sys.setenv(JAVA_HOME="C:\\Program Files\\Java\\jdk1.8.0_201")
Note: jdk1.8.0_201 will be changed depending on the version of Java development kit
Now you can install and load rJava package without any problem.
The problem was rJava wont install in RStudio (Version 1.0.136). The following worked for me (macOS Sierra version 10.12.6) (found here):
Step-1: Download and install javaforosx.dmg from here
Step-2: Next, run the command from inside RStudio:
install.packages("rJava", type = 'source')
On Arch Linux, I needed to install openjdk-src to get a JNI path working.
In other words, these are the packages I needed to install before sudo R CMD javareconf ran successfully:
local/jdk-openjdk 14.0.2.u12-1
OpenJDK Java 14 development kit
local/jre-openjdk 14.0.2.u12-1
OpenJDK Java 14 full runtime environment
local/jre-openjdk-headless 14.0.2.u12-1
OpenJDK Java 14 headless runtime environment
local/openjdk-src 14.0.2.u12-1
OpenJDK Java 14 sources
Assuming you have sudo privileges and not in Ubuntu where package manager makes this easier -- I tried variations of prior answers and found this gem on Databricks blog for nonUbuntu (https://kb.databricks.com/r/install-rjava-rjdbc-libraries.html)
Installed JDK
sudo apt-get install openjdk-8-jdk
Verify path to libjvm.so; for me-->
cd /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64
grep -r libjvm
output:
Binary file server/libjvm.so matches <<<<<<<<
Do java configure
sudo R CMD javareconf
Remove prior versions of the package and install 'rJava' from CRAN mirror in RStudio
Restart RStudio
In RStudio verify link to libjvm.so
dyn.load('/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so')
library('rJava')
I've encountered similar problem on Ubuntu 16.04 and was able to solve it by creating a folder named "default-java" in /usr/lib/jvm and copying into it all the contents of the /usr/lib/jvm/java-8-oracle. I opted for this solution as correcting JAVA_HOME environment variable turned out to be of no use.

Installing Rmpi on Ubuntu 16.04 VirtualBox

I created a new ubuntu-16.04.2-desktop-amd64 machine on VM VirtualBox and I want to be able to use the R environment with Rmpi.
Both of the below approaches gives a similar error.
Updated simplified pre-build binary approach:
When Ubuntu had installed I opened a terminal and executed the following commands:
~$ sudo apt-get update
~$ sudo apt-get install openmpi-bin
~$ sudo apt-get install r-base
~$ sudo apt-get install r-cran-rmpi
~$ R
This opened the R terminal and I invoking the follow function which resulted in an error:
> library(Rmpi)
libmpi.so: cannot open shared object file: No such file or directory
Error : .onLoad failed in loadNamespace() for 'Rmpi', details:
call: fun(libname, pkgname)
error: Cannot start MPI_Init(). Exit
Error: package or namespace load failed for ‘Rmpi’
Alternative approaches that I have attempted include using a local OpenMPI installation and using the R function install.packages to install the Rmpi package (see below). These all resulted in the same error.
I have also tried using MPICH by substituting ~$ sudo apt-get install mpich as the second command in the above procedure (including using the R function for installing the package) which results in an even more onerous runtime error.
Does anyone know what I have done wrong or what I can do to resolve this installation error?
Or alternatively, have anyone been able to successfully install a VirtualBox machine with Rmpi using any Linux distro or an image with pre-installed components?
Original local installation approach:
I have followed the instructions on this blog to download OpenMPI version 2.1.0, compile and install it. However when I try to install the package in R with:
> install.packages("Rmpi", configure.args =
c("--with-Rmpi-include=/home/jormunr/openmpi/include",
"--with-Rmpi-libpath=/home/jormunr/openmpi/lib",
"--with-Rmpi-type=OPENMPI",
"--with-mpi=/home/jormunr/openmpi/"))
it gives the following error
Error: .onLoad failed in loadNamespace() for 'Rmpi', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/jormunr/R/x86_64-pc-linux-gnu-library/3.2/Rmpi/libs/Rmpi.so':
libmpi.so.20: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
I can see that the 'libmpi.so.20' file is in the /home/jormunr/openmpi/lib that I provided as one of the parameter to the installation.
[Disclaimer: I am not a Linux expert and merely have user level skills. Any contributions or corrections from an expert will be greatly appreciated.]
Pre-build Binary Approach
Although trying various ways to install the prebuilt binaries I did not manage to get this option to work. This involved executing in the terminal the command 'sudo apt-get install r-cran-rmpi' to install the r-cran-rmpi prebuilt packages which also automatically installs the libopenmpi1.10 package that is a listed prerequisite. However, it appears that the file 'libmpi.so' is not included in the libopenmpi1.10 package but expected by the Rmpi library which causes an error in the R environment that it cannot find this file.
Local Installation Approach
The local installation did eventually succeed with a few amendments. I created a new ubuntu-16.04.2-desktop-amd64 VirtualBox image with default settings, except for 2048MB of memory and 32GB of hard drive space. When installed I opened a terminal and executed the commands from the Jovinge Lab website with the inclusion of the penultimate command which amends the run-time link editor's path and enables the install.package() function of R to find the 'libmpi.so' file. (also changed the version to 1.10.6 as this is the latest version release of version 1 – see below for version 2)
~$ cd /home/jormunr
~$ wget https://www.open-mpi.org/software/ompi/v1.10/downloads/openmpi-1.10.2.tar.gz
~$ tar -zxvf openmpi-1.10.6.tar.gz
~$ cd openmpi-1.10.2
~$ ./configure --prefix=/home/jormunr
~$ make
~$ make install
~$ sudo apt-get install r-base
~$ export LD_LIBRARY_PATH=/home/jormunr/lib:$LD_LIBRARY_PATH
~$ R
This opens an R terminal and I invoked the function:
> install.packages("Rmpi", configure.args =
+ c("--with-Rmpi-include=/home/jormunr/include/",
+ "--with-Rmpi-libpath=/home/jormunr/lib/",
+ "--with-Rmpi-type=OPENMPI",
+ "--with-mpi=/home/jormunr/"))
This now executed without errors and I could test it with the following R statements:
> library("Rmpi")
> mpi.spawn.Rslaves()
master (rank 0, comm. 1) of size 2 is running on: Valhalla
slave1 (rank 1, comm. 1) of size 2 is running on: Valhalla
> mpi.close.Rslaves()
[1] 1
> mpi.quit()
When I tried this process with the OpenMPI Version 2.1.0 the installation completed successfully but the above test had issues; the mpi.spawn.Rslaves() function completed but mpi.close.Rslaves() did not complete – it never returned and the terminal was left hanging.
I experienced similar challenges. I landed on this solution where libopenmpi-dev was the secret.
sudo apt-get install openmpi-common openmpi-bin libopenmpi-dev r-base
sudo apt-get install r-cran-rmpi
sudo su
R
install.packages("doMPI", dependencies=TRUE)

R: rJava package install failing

When installing rJava using the install.packages("rJava") command I get the following error:
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/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include -I/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include/linux'
java libs : '-L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/amd64/server -L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/amd64 -L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm'
checking whether JNI programs can be compiled... yes
checking JNI data types... configure: error: One or more JNI types differ from the corresponding native type. You may need to use non-standard compiler flags or a different compiler in order to fix this.
ERROR: configuration failed for package ‘rJava’
I have the Java JDK installed and java -version returns the following:
$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
When Googling around for the error I see that others are having the same issue but not finding a solution other than "install the whole JDK, not just the JRE" which I have done.
The other thing I read was to run sudo R CMD javareconf which runs quite happily with no errors.
Any ideas what my problem is?
[[EDIT]]
It's been a few months since I had this problem. I had initially solved this by editing my Java paths, as illustrated in the answer I posted below. I recently ran into the same issue on a new Ubuntu install. I tried Dirk's recommendation to use apt-get to install the rJava package. It worked perfectly. What I failed to appreciate initially is that installing packages using the Ubuntu apt-get method is fundamentally different than just loading the same package using install.packages() inside of R. The Ubuntu packages solve some issues which I didn't realize or appreciate.
Wouldn't
apt-get install r-cran-rjava
have been easier? You could have asked me at useR! :)
Turns out my problem was an issue with my JAVA_HOME environment variable. Yes, shocking I know. My initial setting for PATH and JAVA_HOME looked like this:
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin
And I added /jre so it now looks like this:
export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export PATH=$PATH:$JAVA_HOME/bin
Everything in Java seemed to work fine without the /jre but rJava would not. Odd.
That is how I make it work :
In Linux (Ubuntu 16.04 and 20.04 worked confirmed)
sudo apt-get install default-jre
sudo apt-get install default-jdk
sudo R CMD javareconf
in R:
install.packages("rJava")
Thanks - your suggestion about $JAVA_HOME lead me to a similar solution:
unset JAVA_HOME
before invoking R.
I came across the same issue, and it worked after running commands below.
export JAVA_LIBS="$JAVA_LIBS -ldl"
R CMD javareconf
See details at
http://www-01.ibm.com/support/knowledgecenter/SSPT3X_3.0.0/com.ibm.swg.im.infosphere.biginsights.install.doc/doc/install_install_r.html
This worked for me on Ubuntu 12.04 and R version 3.0
cd /usr/lib/jvm/java-6-sun-1.6.0.26/include
this is the directory that has jni.h
Next create a soft link to another required header file (I'm too lazy to find out how to include more than one directory in the JAVA_CPPFLAGS option below):
sudo ln -s linux/jni_md.h .
Finally
sudo R CMD javareconf JAVA_CPPFLAGS=-I/usr/lib/jvm/java-6-sun-1.6.0.26/include
below is one of my answers on another post - error: unable to load installed packages just now
(this is also relevant to this question)
For Linux(Ubuntu) users: If you have oracle-java (7/8) installed. It'll be at this location /usr/lib/jvm and sudo access is required.
Create the file /etc/ld.so.conf.d/java.conf with the following entries:
/usr/lib/jvm/java-8-oracle/jre/lib/amd64
/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server
(Replace java-8-oracle with java-7-oracle depending on your java version)
Then:
sudo ldconfig
Restart RStudio and then install the rJava package.
Running R under Gentoo on an AMD64. I upgraded to R 2.12.0
R version 2.12.0 (2010-10-15)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)
and those pesky messages went away.
Jan Vandermeer
I tried to install openjdk-7-* but still I had problems installing rJava. Turns out after I restarted my computer, then there was no problem at all.
so
sudo apt-get install openjdk-7-*
RESTART after installing java, then try to install package "rJava" in R
The rJava package looks for the /usr/lib/jvm/default-java/ folder. But it's not available as default. This folder have a symlink for the default java configured for the system.
To activate the default java install the following packages:
sudo apt-get install default-jre default-jre-headless
Tested on ubuntu 17.04 with CRAN R 3.4.1
What worked for me was changing JAVA_HOME from file /usr/lib/R/etc/javaconf
I first checked what was my version of Java enabled : sudo update-alternatives --config java.
In my case, it was java-8-oracle
I opened the file /usr/lib/R/etc/javaconf and replaced default-java by java-8-oracle :
${JAVA_HOME=/usr/lib/jvm/default-java}
replaced by :
${JAVA_HOME=/usr/lib/jvm/java-8-oracle}
And then sudo R CMD javareconf
I restarted RStudio, and could then install rJava.
what I do is here:
in /etc/apt/sources.list, add:
deb http://ftp.de.debian.org/debian sid main
Note:the rjava should be latest version
2 run:
sudo apt-get update
sudo apt-get install r-cran-rjava
Once update the old version of rjava, then can install rhdfs_1.0.8.
I got it working by downloading : https://cran.r-project.org/src/contrib/rJava_0.9-8.tar.gz and running command R CMD install rJava_0.9-8.tar.gz
I was facing the same problem while using Windows 10. I have solved the problem using the following procedure
Download Java from https://java.com/en/download/windows-64bit.jsp for 64-bit windows\Install it
Download Java development kit from https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html for 64-bit windows\Install it
Then right click on “This PC” icon in desktop\Properties\Advanced system settings\Advanced\Environment Variables\Under System variables select Path\Click Edit\Click on New\Copy and paste paths “C:\Program Files\Java\jdk1.8.0_201\bin” and “C:\Program Files\Java\jre1.8.0_201\bin” (without quote) \OK\OK\OK
Note: jdk1.8.0_201 and jre1.8.0_201 will be changed depending on the version of Java development kit and Java
In Environment Variables window go to User variables for User\Click on New\Put Variable name as “JAVA_HOME” and Variable value as “C:\Program Files\Java\jdk1.8.0_201\bin”\Press OK
To check the installation, open CMD\Type javac\Press Enter and
Type java\press enter
It will show
In RStudio run
Sys.setenv(JAVA_HOME="C:\\Program Files\\Java\\jdk1.8.0_201")
Note: jdk1.8.0_201 will be changed depending on the version of Java development kit
Now you can install and load rJava package without any problem.
The problem was rJava wont install in RStudio (Version 1.0.136). The following worked for me (macOS Sierra version 10.12.6) (found here):
Step-1: Download and install javaforosx.dmg from here
Step-2: Next, run the command from inside RStudio:
install.packages("rJava", type = 'source')
On Arch Linux, I needed to install openjdk-src to get a JNI path working.
In other words, these are the packages I needed to install before sudo R CMD javareconf ran successfully:
local/jdk-openjdk 14.0.2.u12-1
OpenJDK Java 14 development kit
local/jre-openjdk 14.0.2.u12-1
OpenJDK Java 14 full runtime environment
local/jre-openjdk-headless 14.0.2.u12-1
OpenJDK Java 14 headless runtime environment
local/openjdk-src 14.0.2.u12-1
OpenJDK Java 14 sources
Assuming you have sudo privileges and not in Ubuntu where package manager makes this easier -- I tried variations of prior answers and found this gem on Databricks blog for nonUbuntu (https://kb.databricks.com/r/install-rjava-rjdbc-libraries.html)
Installed JDK
sudo apt-get install openjdk-8-jdk
Verify path to libjvm.so; for me-->
cd /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64
grep -r libjvm
output:
Binary file server/libjvm.so matches <<<<<<<<
Do java configure
sudo R CMD javareconf
Remove prior versions of the package and install 'rJava' from CRAN mirror in RStudio
Restart RStudio
In RStudio verify link to libjvm.so
dyn.load('/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so')
library('rJava')
I've encountered similar problem on Ubuntu 16.04 and was able to solve it by creating a folder named "default-java" in /usr/lib/jvm and copying into it all the contents of the /usr/lib/jvm/java-8-oracle. I opted for this solution as correcting JAVA_HOME environment variable turned out to be of no use.

Resources