Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an uniform way to detect the installed java on linux?

Tags:

java

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

REPHRASE: If I need 64-bit JDK on Linux, how do I programatically check that it is present and inform the user that he has some other java instead?

like image 271
m_pGladiator Avatar asked Feb 22 '23 14:02

m_pGladiator


2 Answers

You can always use java -version.

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

like image 193
Mahmoud Hanafy Avatar answered May 01 '23 04:05

Mahmoud Hanafy


No unified way. You can use JAVA_HOME env. variable but it is not defined on all machines. But there is a "common" way like ls /usr/java/*/bin/java | tail -1.

This should give in most cases you the latest version.

like image 38
AlexR Avatar answered May 01 '23 05:05

AlexR