Ubuntu does not come with any Java installed, unlike Linux Mint which comes at least with openJDK. The rJava package in R requires a JDK to exist in the system. If one uses Oracle Java, then at this point, he may want to install Oracle Java instead of openJDK. This process is very simple:
1. Download Oracle JDK archive
2. Extract to a location with user access, say $HOME/apps/jdk1.7
3. Add/ modify 2 environment variables: Create/ open $HOME/.bashrc and add to the end:
4. Since this is the only java, we dont need the update-alternatives. That would be required in Mint, since the default /usr/bin/java would be provided by the pre-installed openJDK.
Now, we want to configure Java for R, using
$ sudo R CMD javareconf
This searches for java in the PATH, then configures R to use that Java (does not modify any system environment variable). The problem with this command is that by default, it picks JAVA_HOME as $JDK_HOME/jre, instead of $JDK_HOME. Because of this, R thinks that only JRE exists in the system, and not JDK (which it requires). Hence, instead of above command, we give
$ sudo R CMD javareconf JAVA_HOME=/home/user/apps/jdk1.7
where ‘user’ is the username. This is the JAVA_HOME that we want R to have in its javaconf, because this is the JDK_HOME and not JRE_HOME.
Also, the JAVA_HOME system environment variable takes precedence over the one in R javaconf, hence we must remove it. If
$ echo $JAVA_HOME
returns something, it means at some point we had set the variable, so we must remove it. The command for R javareconf earlier would not set it, because as mentioned it does not create/ modify any system environment variables. To remove it,
$ unset JAVA_HOME
At this point, we have configured R javaconf, and ensured that JAVA_HOME is not set in the system. It therefore exists only in R javaconf. Open R (or RStudio), and install rJava:
If behind a proxy, we can set R env var http_proxy. Open $HOME/.Renviron (create if does not exist) and add the line having format: