Skip to main content

Using multiple Java versions on CS Linux workstations

Department Linux workstations (including the Junkfood cluster and yogurt) have more than one JDK installed side by side, so you can match whichever version a particular class, tool, or the Submit server expects, without losing the others.

Listing the Java versions installed on a machine

A quick way to see what’s installed is to list /usr/lib/jvm:

ls /usr/lib/jvm

For more detail — including which one java currently resolves to — RHEL manages JDKs through the alternatives system:

alternatives --display java

This lists every registered JVM, its full path under /usr/lib/jvm/, and which one is the current “best”/default. The same works for javac, jar, and the other JDK tools (alternatives --display javac, etc.).

To check what version you’d actually get right now without any of the above:

java -version

Using a specific version for one command or session

Regular user accounts can’t change the system-wide default (that requires root — see below), but you don’t need to: you can point at a specific JDK just for your own shell or command.

Full path, e.g. to run Java 21 explicitly regardless of the current default:

/usr/lib/jvm/java-21-openjdk/bin/java -version

Or set JAVA_HOME and prepend it to your PATH for the rest of your shell session (add this to your shell profile if you want it every time you log in):

export JAVA_HOME=/usr/lib/jvm/java-21-openjdk
export PATH="$JAVA_HOME/bin:$PATH"

Swap java-21-openjdk for java-17-openjdk (or whichever version you need) — the unversioned symlinks under /usr/lib/jvm/ (java-17-openjdk, java-21-openjdk, etc.) always point at the currently installed build of that major version, so you don’t need to track exact point-release numbers.

Changing the machine-wide default

alternatives --set java <path> changes which version plain java resolves to for everyone on that machine, and requires root. Since this is a shared, per-machine setting rather than a per-user one, please don’t ask a friend/labmate with root to flip it on a whim — if you have a real need for the department-wide default on a shared workstation to change, contact helpdesk@cs.umd.edu. For anything specifically about matching the Submit build servers’ Java version, submit-help@cs.umd.edu is the better first stop.