About Me

header ads

[Guide] jEnv, simplify management of multiple versions of Java on Linux

java-logo

jEnv is a tool, developed for GNU/Linux systems, which simplifies the management of the various versions of Java. Very useful for programmers, who can, for example, use it to test the compatibility of their software between the different language releases.

jEnv: Java version management system

In 2020, the Java language turned 25 and, in March, version 14 was released. Language of hatred and love continues to be one of the protagonists in the IT world. jEnv, a handy utility from CLI, simplifies the management of the different versions of Java. Many programmers, in fact, still use Java 8, or maybe the latest LTS, but still want to test their creations with later or earlier versions. jEnv allows you to set a version of Java globally, but also to specify a specific version to be used for a single project.

jenv-java-768x402

As a first step, of course, you need to install the tool, giving the following instructions:

git clone https://github.com/jenv/jenv.git ~/.jenv
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(jenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
jenv enable-plugin export
exec $SHELL -l #riavvia la shell

After the installation phase, to verify that the procedure has been completed, just give the following directive from the terminal:

jenv doctor

Getting an output similar to that shown in the previous screenshot, it means that you have configured it correctly.

How to use the tool

To use jEnv, of course, you need to connect the various Java environments installed on your system. In my case, they are version 11 and 14 of OpenJDK, so I will use these directives:

jenv add /usr/lib/jvm/java-11-openjdk-amd64/
jenv add /usr/lib/jvm/java-14-openjdk-amd64/

To verify that the process has been successful, just give the jenv versions command. This will show the various versions of the language, which can be managed through the utility. To change the version of Java in use, globally, instead, use the jenv global openjdk64-11.0.7 directive. Obviously replacing, in this last instruction, the version that I have indicated in the example, with the one present in your computer.

jenv-global-768x402
How to change the Java version globally with jEnv.

If, on the other hand, you prefer not to change the overall system behavior, but only the version to be used for a specific project, thanks to jEnv it is possible to set a specific version of Java for each individual folder. Go to the desired directory and give the following instruction:

jenv local openjdk64-14.0.1

Similarly for the shell:

jenv shell openjdk64-14.0.1

By doing so, following the example, you will have Java 11 globally, while for that specific project, or for that shell, the latest version of the language available.

For more information on this utility, as always, I refer you to the official GitHub page.

Post a Comment

0 Comments