---
title: "Installing rJava locally"
canonical: "https://kb.uconn.edu/space/SH/26312540212/Installing%20rJava%20locally"
format: markdown
---
> ℹ️ For more information on how to install `R` packages locally, see [https://uconn.atlassian.net/wiki/spaces/SH/pages/26033587623](https://uconn.atlassian.net/wiki/spaces/SH/pages/26033587623).

To install the `rJava` package locally, you must load the `OpenJDK` module and set some environment variables.

To load both `openjdk` and `r`, run:

```
module load openjdk/18.0.1.1 r/4.2.2
```

The variables that need to be set up are:

```
export JAR="$JAVA_HOME/bin/jar"
export JAVA="$JAVA_HOME/bin/java"
export JAVAC="$JAVA_HOME/bin/javac"
export JAVA_LIBS="-L$JAVA_HOME/lib/server -ljvm"
export JAVA_CPPFLAGS="-I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
export JAVA_LD_LIBRARY_PATH="$JAVA_HOME/lib/:$JAVA_HOME/lib/server"
```

Finally, start an `R` session and install the package (assuming your local libraries are stored in `~/rlibs`:

```shell
R
.libPaths("~/rlibs")
install.packages("rJava", lib = "~/rlibs", repo = "https://cloud.r-project.org/")
```

Once the package is installed, the environment variables don’t need to be set up every time you use it.