{{announcement.body}}
{{announcement.title}}

Managing Multiple Java Installations

DZone 's Guide to

Managing Multiple Java Installations

Learn more about managing Java installation.

· Java Zone ·
Free Resource

Multiple cups of coffee

Learn more about managing Java installation.

With more and more Java releases coming up, it’ll be more interesting to manage multiple Java installations on your local environment. Different projects may require different Java versions.

You may also like: How to Install Multiple Versions of Java on the Same Machine

The jenv project is a convenient way how to manage Java installations. It can set up local Java installations on a global, directory, and shell level and uses easy-to-remember Java version identifiers:

$> jenv versions
  11
  12.0
  13.0
  1.8
* 1.8.0.152
  9.0
  9.0.4
  openj9-jdk-12.0.1
  openj9-jdk-13.0.1
  openjdk64-11.0.2
  openjdk64-12.0.1
  openjdk64-13.0.1
  oracle64-1.8.0.152
  oracle64-9.0.4

# switch to JDK 13 globally
$> jenv global 13.0

# switch to JDK 9 locally
$> cd project/
$> jenv local 9.0

$> java -version
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

$> cd .. && java -version
openjdk version "13.0.1" 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 13.0.1+9)
Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.17.0, ...)


Jenv stores the local Java version in a .java-version file.

Jenvs works by declaring wrapper java binaries that direct to the corresponding installation based on the context.

Shell scripts can also set a specific version via the JENV_VERSION environment variable:

#!/bin/bash

JENV_VERSION='13.0'

# will use JDK 13
java -version


Some of the content of this post was reposted from my newsletter issue 025.

Further Reading

How to Install Multiple Versions of Java on the Same Machine

No More JRE Packaging? No Big Deal

Topics:
installations, java, jenv, multiple installations

Published at DZone with permission of Sebastian Daschner , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}