Trouble installing R from homebrew formula (Intel Mac Pro) - r

I'm having trouble installing R from a homebrew formula on our Intel garbage can mac pro at work. I was having trouble installing tidyverse from source code so I removed and have been attempting to reinstalling R, as I thought it might have been a version mismatch somewhere.
I used
brew install R
and after a bunch of output where it's downloading other packages, I get back the following
==> Installing dependencies for r: libpng, freetype, fontconfig, gettext, libffi, pcre, glib, pkg-config, libpthread-stubs, xorgproto, libxau, libxdmcp, libxcb, libx11, libxext, libxrender, lzo, pixman, cairo, gmp, isl, mpfr, libmpc, lz4, xz, zstd, gcc, jpeg-turbo, openblas, pcre2, readline, ca-certificates, openssl#1.1 and tcl-tk
==> Installing r dependency: libpng
Unknown option: -C
usage: git [--version] [--help] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
Error: Command failed with exit 129: git
Is this in fact a git error? What is the -C command?
Things I've tried:
removing and reinstalling command line tools
removing and reinstalling Homebrew
My machine:
Mac Pro (Late 2013)
2.7 GHz 12-Core Xeon E5
Thanks!
Sam

I think it tries to use an old version of git at /usr/bin/git, but you need to run brew install git to install a newer version of git to /usr/local/bin/git.
If /usr/local/bin/ isn't on your PATH before /usr/bin/, then you can add a line like this to ~/.bash_profile:
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
However /usr/local/bin is included in /etc/paths by default, so it should be added to PATH by programs that run path_helper (like Terminal and iTerm 2 but not Script Editor or Emacs.app).

Related

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.

R, issue "unable to load shared object cairo.so" on Linux CentOS 7

I've been using R with ggplot2 and other packages on my Linux CentOS 7 for a long time.
Today, all of a sudden, it stopped working.
When I call the png() function in my script, it generates the following errrors:
Warning messages:
1: In png(heatmap_file) :
unable to load shared object '/usr/lib64/R/library/grDevices/libs//cairo.so':
/lib64/libcairo.so.2: undefined symbol: FT_Get_Var_Design_Coordinates
2: In png(heatmap_file) : failed to load cairo DLL
I tried to update the cairo package many times but nothing worked out so far.
What can I do?
Thanks!
Your version of cairo (/lib64/libcairo.so.2) depends on a function called FT_Get_Var_Design_Coordinates. This function should come from FreeType. However, your version of libfreetype.so seems to be older and does not have this symbol. So, either you explicitly installed an older version, or "something" comes with an older version of FreeType.
I would look for files called libfreetype.so and check if they have the necessary symbol
I'm on Debian testing and here I get (this means that my version of FreeType does have this symbol; you would get no output if the symbol is not available):
$ nm -s -D /usr/lib/x86_64-linux-gnu/libfreetype.so | grep FT_Get_Var_Design_Coordinates
000000000001d260 T FT_Get_Var_Design_Coordinates
For you, based on the path to libcairo.so, I would expect something like /lib64/libfreetype.so to be the path to check.
I found a solution and I am going to share it with the community.
I am working on a Dell Latitude 3540 laptop running Linux CentOS 7 operating system (centos-release-7-3.1611.el7.centos.x86_64).
I ran sudo yum -y update and I understood there was a duplication issue regarding the freetype package, which was installed twice, and some other packages that were having conflicts.
I then removed the old freetype package and the conflicting packages with this command:
rpm -e freetype-2.4.11-12.el7.i686 --nodeps
rpm -e conflicting-package-1 --nodeps
rpm -e conflicting-package-2 --nodeps
...
Then I updated all the packages I manually removed:
sudo yum -y update freetype
sudo yum -y conflicting-package-1 freetype
sudo yum -y conflicting-package-2 freetype
...
This method worked out for me; I hope it might be helpful to someone.

Installing R on Linux: configure: WARNING: you cannot build PDF versions of the R manuals

While configuring R on Debian GNU/Linux 8.8 (jessie) I am getting the warning above. Any ideas which package should be installed to solve the issue and have the manuals build as PDF?
A possible solution is to install LaTeX:
sudo apt-get install texlive
This enables production of PDF but leaves a warning on missing sty files open:
configure: WARNING: neither inconsolata.sty nor zi4.sty found: PDF vignettes and package manuals will not be rendered optimally
To solve the issue, install the extra fonts package to texlive
sudo apt-get install texlive-fonts-extra
On Fedora:
sudo dnf install texlive-inconsolata
This will install the inconsolata font, which is the font that R uses for the manual. See Rd.sty.

OSX Installing Rsymphony - linking headers and libs

symphony is correctly installed and tested in terminal. R complains about missing header and libraries when trying to install Rsymphony from source. Any pointers are HIGHLY appreciated. thank you!
symphony installation directory: /Users/timo/Applications/symphony/
R install command:
install.packages("Rsymphony", configure.args="--with-SYMPHONY-include=/Users/timo/Applications/symphony/include/ --with-SYMPHONY-lib=/Users/timo/Applications/symphony/lib",type="source")
results in :
* installing *source* package ‘Rsymphony’
** package ‘Rsymphony’ successfully unpacked and MD5 sums checked
Cannot find SYMPHONY libraries and headers.
See <https://projects.coin-or.org/SYMPHONY>.ERROR: configuration failed for package ‘Rsymphony’* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rsymphony’* restoring previous‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rsymphony’
I also struggled to get Rsymphony installed, but finally got it working after many hours of messing around. Here's what I did, hopefully it'll save others some time. This works on Mac OS El Capitan (10.11) and R 3.3.0.
First, install the homebrew package manager if you don't already have it:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Next install SYMPHONY with homewbrew. I found this to be the best approach because it puts everything in the right place:
brew tap coin-or-tools/coinor
brew install symphony
Now install pkg-config, a tool for querying installed libraries for when compiling software source code. Not sure if this is strictly necessary, but pkg-config is used in the configuration script for Rsymphony:
brew install pkg-config
At this point Rsymphony should now be able to find the necessary SYMPHONY libraries, however, I still got the following compiler error:
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lgfortran
Apparently it has something to do with needing a different version of the fortran compiler. This helpful post with instructions for getting the correct compiler saved me. Run the following commands:
curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /
Now, finally, you should be able to install Rsymphony with:
install.packages("Rsymphony", type = "source")
SOLUTION:
I have found the solution in this link (...I got RSymphony to install, but it involved some hacking ...)
Installing RSymphony using RStudio on macOS
I had also this issue: ..no checking for COIN-OR package CoinUtils... and it was solved by "export PKG_CONFIG=/usr/local/bin/pkg-config; export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/"

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