Fix the libjvm.so file not found error
I encounter this problem whenever I try to use rJava
on Ubuntu + Rstudio, so I decided to write it down.
You’ll see this error message if you try to load the rJava
package or anything else that depends on it (psData
in my case):
The issue boils down to Rstudio being unable to find the shared file libjvm.so
. We need to include the path towards libjvm.so
(i.e. the Java library folder) in LD_LIBRARY_PATH, the environment variable that points Ubuntu and its application towards shared library.
A wrinke: If we set LD_LIBRARY_PATH
in /etc/environment
, library(rjava)
can be loaded via terminal R
. However, Rstudio doesn’t look into /etc/environment
and thus is still not aware of the new LD_LIBRARY_PATH
.
The upshot: Set LD_LIBRARY_PATH
in ~/.profile
to make it available to all desktop applications, including Rstudio (as suggested by Ubuntu wiki article on persistent environment variable).
Instructions:
- Inside
~/.profile
, add the path tolibjvm.so
toLD_LIBRARY_PATH
(you may have a different path from mine):
- Log out and in or restart your computer so that Ubuntu reloads
~/.profile
. - Then make R update its java configuration:
That’s it. library(rJava)
should run after restarting Rstudio.
Leave a Comment