< 1 minute read

Get java version in linux using a one liner

Command: java -version

Output:

openjdk version "1.8.0_192"
OpenJDK Runtime Environment (Zulu 8.33.0.2-win64) (build 1.8.0_192-b01)
OpenJDK 64-Bit Server VM (Zulu 8.33.0.2-win64) (build 25.192-b01, mixed mode)

So, here how do I fetch 1.8.0_192 ?

Use below command, this redirects the stderr to stdout and then filters the java version number.

java -version 2>&1|awk -F\" '/version/ {print $2}'

Simon

I am a Fullstack developer and Consultant with an experience of 9+ years in the industry. I mainly work on Java, React, Javascript, NodeJs, Elasticsearch and Botpress.

0 Comments

Leave a Reply

Avatar placeholder

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.