Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash command to check if Oracle or OpenJDK java version is installed on Linux

Tags:

java

linux

bash

I need a bash line to check if java version currently installed is Oracle's or OpenJDK.

A one-liner by parsing the output of the java -version command:

java -version 

java Oracle output:

java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode) 

java OpenJDK Output:

java version "1.7.0_91" OpenJDK Runtime Environment (amzn-2.6.2.2.63.amzn1-x86_64 u91-b00) OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode) 
like image 986
Basil Musa Avatar asked Apr 06 '16 08:04

Basil Musa


People also ask

How do you check Oracle JDK is installed or not?

Open command prompt and enter “java –version”. If installed version number is displayed.

How do I know where Java is installed on Linux?

This depends a bit from your package system ... if the java command works, you can type readlink -f $(which java) to find the location of the java command.

What is the command for verifying if Java is installed in Linux?

To check which version of Java is installed, follow this procedure: -Open a Linux command prompt. -Enter the command java -version. -If Java version is installed on your system, you see a Java installed response.


1 Answers

if [[ $(java -version 2>&1) == *"OpenJDK"* ]]; then echo ok; else echo 'not ok'; fi 
like image 152
Cortwave Avatar answered Oct 05 '22 16:10

Cortwave