Is there a single way to detect installed Java on Linux?

Is there a way to detect java installed on different Linux distributions? With Windows, you can use JAVA_HOME or the registry for this, but Linux? Could this be detected if it is JDK, JRE, 32 or 64 bit?

REPHRASE: if I need a 64-bit JDK on Linux, how can I programmatically verify that it is present and tell the user that it has another Java?

+4
source share
5 answers

You can always use java -version .

This works on all platforms, but make sure Java is included in the PATH system variable.

+5
source

There is no single way. You can use JAVA_HOME env. variable, but not defined on all machines. But there is a β€œgeneral” way, like ls /usr/java/*/bin/java | tail -1 ls /usr/java/*/bin/java | tail -1 .

In most cases, you will be provided with the latest version.

+1
source

To see the file invoked by the java command, use which java , although this will often be just a symbolic link to the real executable, for example /usr/bin/java . As far as I know, this works on all distributions.

On some Linux distributions, you can use update-alternatives --display java (possibly with sudo ) to see a list of all the java executables installed on your system and also tell you which symbol the link refers to. You can switch between them using the --config option.

+1
source

You can use java -version in the terminal to find out some information.

+1
source

There are many answers here to help check if Java is installed. If so, you can get more information programmatically. SystemUtils commons-lang provides you with a lot of information about the actually running version of Java.

0
source

All Articles