Take the 2-minute tour ×

So I need to get access to an MSSQL server in my Rapache program and when I try to load RJDBC as a library in my Rapache code I get server error. In the logs it looks like this:

      error: unable to load shared object '/usr/lib/R/site-library/rJava/libs/rJava.so':
      libjvm.so: cannot open shared object file: No such file or directory
    Error: package/namespace load failed for 'rJava'
    5: stop(gettextf("package/namespace load failed for %s", sQuote(package)), 
   call. = FALSE, domain = NA)
    4: library(rJava)
    3: eval.with.vis(expr, envir, enclos)
    2: eval.with.vis(ei, envir)
    1: source("/var/www/brew/optimization.R")
    [Fri Jun 15 13:57:29 2012] [error] [client] File does not exist:  /var/www/favicon.ico

Also I checked and rJava.so exists in that directory. Is it something with libjvm.so?

The thing is when I run this library(RJDBC) in just R it says this:

    Loading required package: DBI
    Loading required package: rJava
    Warning message:
    replacing previous import 'show' when loading 'rJava'

and then all my RJDBC code aftewards works fine. So is this a problem with some Java configuration or is this a problem with rApache not being able to run the library because of the warning message?

share|improve this question
add comment

2 Answers

Yes, it is something with libjvm.so ;) rjava.so cannot find it!

Various linux distros (I presume you're running linux?) will start apache in a restricted environment thus limiting where the process can find shared libraries. I recommend looking through the shell scripts to see if this is happening.

I'd also investigate your dynamic linker run-time binding configuration, e.g., the /etc/ld.so.* files along with the ldconfig command.

Try running your code from your personal R session. If it doesn't run there, then you need to fix your java/rJava install first. If it does run there, then explore the topics I discussed above.

Oh, and I just remembered: rJava may source in some java specific environment variables, located in the rJava package installation. See if that's happening in your local session. If that's the case then you will most likely need these set when apache/rApache is run.

And as I mentioned above, if your distro is restricting apache's environment, then you'll have to shim those Java envirnment variables into that restriction process.



share|improve this answer
Sorry I am really new to this. Can you go more in depth on how I would find these java environment variables and allow them in Apache –  Nick Trileski Jun 18 '12 at 16:59
add comment

I had the same issue and determined the cause to be that rApache was not setting the LD_LIBRARY_PATH environment variable. This needs to be set before an R environment is created for rJava (or any packages that depend on it) to initialize correctly (i.e. be able to find the path to libjvm.so).

You can check this with a simple test script:

cat(Sys.getenv()['LD_LIBRARY_PATH'], '\n')

Unfortunately, the simple fix using a SetEnv directive to Apache doesn't work. Instead you need to do the following:

(Note the following was done on a 64-bit RHEL5 Server)

Add a file to /etc/ld.so.conf.d called rApache_rJava.conf with the following contents:


(the above line was the path to the parent directory of libjvm.so on my server)

As root:

$ /sbin/ldconfig

followed by restarting Apache

After Apache restarts you should be able to run R-scripts via rApache that depend on rJava, e.g. anything with lines like:


The process above with additional reference links is also outlined here, on my blog: http://oddhypothesis.blogspot.com/2012/06/making-rapache-load-rjava.html

EDIT: Full Disclosure

The blog linked to above is my own

share|improve this answer
I edited your post just to add a quick disclosure that the blog you were linking to was your own. This is a decent answer and it's not inappropriate to post a link like this now and again when it's related and you have provided an extensive answer; you just need to include a disclosure that it's your site you are linking to, is all. :) –  Andrew Barber Nov 20 '12 at 19:51
Here's the FAQ on Self-Promotion, where the requirement for disclosure is mentioned, just FYI. –  Andrew Barber Nov 20 '12 at 19:51
Thanks. I happened to refresh the page which seems to have removed your edit ... re-edited to add disclosure –  oddHypothesis Nov 20 '12 at 22:23
add comment

Your Answer


