rJava is an essential package because it allows accessing rich Java world. There are at least dozens of packages on CRAN which depends on Java (e.g., the excellent rscala for calling scala code from R). However, sometimes installing rJava might be quite problematic. In this post, I’ll focus on the pitfalls found on Linux/Ubuntu, but if you are on Windows following instructions from here, should solve your problem.
R CMD javareconf
One of the first thing that you should try if you have a problem with rJava is to check if you have java installed on your system, by running
java -version in the console. If not you need to install Java JDK (https://stackoverflow.com/a/1906455 - the difference between JRE and JDK). On Ubuntu, this can be done with
sudo apt-get install openjdk-8-jdk (you can replace 8 with the different version of Java). For more information please visit this site.
If you have Java on your machine, you can now run the
R CMD javareconf to reconfigure R with it, and from now you should be able to install and use rJava.