How to check java version in linux

Several copies of Java can be installed on the same computer, and if you have several browsers, each of them may use a different version or not at all. This article describes several ways to check this.

Answer 1.

1. Open a terminal window and type "java -version"
This command should return something like: Java (TM) 2 Runtime Environment, Standard Edition (build 1.6) If it returns -bash: java: command not found, it means either java is not installed or you did not specify the path correctly.
2. Use the free internet testers, go here and click the Check Java version button. Follow the link
In Firefox 3 go to Tools, click on the Add-ons button and go to the Plugins tab.
For Firefox 2 or 3: For Firefox versions 2 and 3, enter: about: plugins in the address bar. If Java is installed, there will be multiple Java entries.
In Internet Explorer 7 or 8, go to Tools, select Internet Options and on the General tab, click on the History Settings button, click the Show Objects button, right-click on the ActiveX control and view its properties. Each ActiveX control has a "base code" and for each of the Java controls it will display a version number.

Answer 2.
if [ -x /usr/bin/java ] ; then
-version 2>&1 | head -1 | awk -F '"' '{print $2}'

OUTPUT (on my linux box):


check if the java executable is present. if so, print the version.

Depends on how you expect it to be installed; there are two ways to find the binary java:

  • look java in PATH (what are you doing while executing java -version)
  • if JAVA_HOME defined, refer to what is the preferred installation and startup $JAVA_HOME/bin/java -version

After that, just extract the version number from the output, As you need.

Answer 3.

a=`(java -version) 2>&1`
if [[ "$a" == *1.7* ]]
Hope the above article is informative. Tp get more tutorials like this please visit us on our official web page.

Leave a Comment

Your email address will not be published. Required fields are marked *