Installing rJava on Ubuntu is a piece of cake. All you have to do the code below, and boom!!! You got rJava working in R.
sudo apt-get install openjdk-7-jdk sudo apt-get install r-cran-rjava export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386 export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/i386:$JAVA_HOME/jre/lib/i386/client
Now, the challenge was trying to get rJava working on RHEL. I could not find any proper documentation that worked. Instead, I ran into a bunch of posts and pointing to things that worked in their environment, but not on mine (so, this might not work on yours as well, but I hope it does). I usually like to give credit to the sources, but this time, they were so many over a long time span, that I could not remember what came from where anymore. So, I apologize for that. Below are the things that I did to get rJava working.
$ sudo yum install gcc-c++ gcc-gfortran R R-core R-core-devel R-devel R-java R-java-devel java-1.7.0-openjdk-devel $ sudo yum list install gcc*
Once, you have installed the necessary packages; then it is time to
configure your environment
$ sudo /usr/sbin/alternatives --config java #select openjdk $ sudo /usr/sbin/alternatives --config javac #select openjdk $ export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-18.104.22.168.x86_64/jre $ export PATH=$PATH:$JAVA_HOME/bin $ sudo /usr/bin/R CMD javareconf $ R > install.packages("rJava") #install rJava on R console
And that is it! If you got the install.packages(“rJava”) to work on R, that means that now you can call Java from within R console.