19

How can I run an application with a specific Java version? I have three Java versions intstalled:

myuser@mysystem:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
 Selection Path Priority Status
------------------------------------------------------------
 0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 auto mode
* 1 /opt/jdk-9.0.4/bin/java 1 manual mode
 2 /opt/jdk1.8.0_162/bin/java 1 manual mode
 3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode

I have Java 9 set as default and I'd like to keep it that way. Still, an application named pdfsam doesn't seem to work properly with Java 9. What command is necessary to run it with openjdk (option 3)?

asked May 22, 2018 at 9:04
1
  • What is the command you use to run your application? Commented May 22, 2018 at 9:39

2 Answers 2

30

You can run java with the absolute path to the installation

This would be your default /usr/bin/java installation

java -version

To change it, use the absolute path

/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -version

If you're not running the java command directly, try setting the JAVA_HOME variable:

JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/" pdfsam
answered May 22, 2018 at 9:38
Sign up to request clarification or add additional context in comments.

Comments

1

As I needed a specific version of Java for a specific application ("Jitsi Desktop" no more supported and works with JDK 8). The only way to get this specific version is to download it, uncompress and make application use it. In my case the JAVA_HOME environment variable does not working since the JDK is not really installed in the system.

So I found this simple method : install the JDK version needed and execute the specific application with specifying which version of JDK using with temporarily modifying the PATH environment variable.

In my case (the user must have right to read and execute the JDK) :

user@host:~$ PATH=/data/noinstall/jdk8u332-b09/bin/:$PATH jitsi

Note : adapt the path of the JDK's bin directory before the colon

So PATH is modified only during the execution of jitsi. Elsewhere during the execution or after the execution, PATH stay unchanged.

As update-alternatives --config java change the JDK globally I suppose this solution makes more comfortable the use cases with many different versions of JDK installed on the same system, dev, etc.

Based on this topic and my intuitions.

answered Apr 20, 2023 at 10:17

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.