Check if active java version is open-jdk or oracle

java -version simply outputs :

java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Need to find out if I am using the oracle version or the open-jdk version.

1

2 Answers

You can write a simple bash script to check this out:

  • Open any text editor (preferrably vim or emacs).
  • create a file named script.sh (or any name with the .sh extension).
  • paste the following code in it:

    #!/bin/bash
    if [[ $(java -version 2>&1) == *"OpenJDK"* ]]; then echo ok; else echo 'not ok'; fi
  • save and exit the editor.
  • Execute the code using bash name.sh (The code return ok if you have a openJDK else not ok).
1

A typical output from running the same command to check the version for an OpenJDK version would be:

$ java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

Sumit Kumar is just checking for this using bash

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like