crimemapping_textbook_bookdown icon indicating copy to clipboard operation
crimemapping_textbook_bookdown copied to clipboard

Easier way to fix rJava on Mac/Linux?

Open mbroedl opened this issue 6 years ago • 2 comments

In Chapter 3 there is a remark of how to fix rJava. It probably works but may send a message of 'this is complicated'. https://github.com/maczokni/crimemapping_textbook_bookdown/blob/d6a568e3460d35668e3bd5bd8ff0cd1f3a45d747/03-week3.Rmd#L404

I use sudo R CMD javareconf (see here) on my Linux. Maybe an idea for the future if this works with Mac?

mbroedl avatar Mar 04 '19 16:03 mbroedl

Does that solve the same thing? If yes then yes do go ahead and change it over! I've included the sudo R CMD javareconf as a step but didn't realise it did same thing as the above.

However that also didn't solve it for some, so I had a step by step guide on the discussion board this year like this:

In your Terminal, type java --version

If that prompts you to download java, then download and install the latest version (when you click more info... it will take you to a page where you can download, get the one at the top of the page)

Once installed (or if the java --version just printed a version), run the command sudo R CMD javareconf in terminal. Read the output.

If you get a bunch of errors, you might need to install xcode. To do that you need to type xcode-select --install in the terminal (see details here: http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/ ).Once you have xcode installed you can keep following these steps.

If you don't get errors, you will see a path where your version of java is installed. Copy that path. Then in R Studio type:

dyn.load('/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/server/libjvm.dylib') but with your path (from terminal) i the place of that path there (in italics here for emphasis)

rJava should now work. It might need a restart of the computer.

Maybe we should include that too.

maczokni avatar Mar 06 '19 16:03 maczokni

I believe the difference is that your ´ln´ links the java library with a symbolic link, while javareconf takes environment variables and writes them system specific into the loaded R libraries.

For the forum post, the second part about dynamic loading should not be necessary with javareconf, assuming that R is restarted (which it will when installing packages, but not when staying 'live').

What might be an issue though is when people just install java as then the environment variables might not be updated when using the same terminal? (Or in windows before the next restart.)

mbroedl avatar Mar 06 '19 16:03 mbroedl