How can I check the Java version on Linux (RedHat 6)?

I’m trying to check java version linux on my machine. When I run:

which java

It returns:

/usr/bin/java

However, when I try:

java -version

The console gets stuck in “Java mode” and waits for input. Nothing happens until I press Ctrl+C.

Why is this happening, and how can I properly check my Java version?

Honestly, the easiest way to check java version linux is the classic go-to command. It works most of the time.

java -version

:white_check_mark: Expected Output:

java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

:warning: Heads-up:

If it hangs or doesn’t return anything, don’t worry—there are other ways to dig in.

Adding on to what @Rashmihasija said—if java -version doesn’t respond, it’s probably a PATH issue. Here’s what I usually do next to check java version linux more directly.

/usr/bin/java -version

:round_pushpin:Still not working? Run this to find the actual binary path:

readlink -f /usr/bin/java

Then use:

$(readlink -f /usr/bin/java) -version

:white_check_mark: Why this helps?

  • Cuts through broken symlinks.
  • Ignores whatever weirdness is happening with PATH settings.
  • Gives you a straight-up answer from the real location of Java.

Great pointers above! But say you’re not even sure Java is properly installed—this is where package management comes in. It’s a reliable way to check java version linux, especially when things seem broken.

Try:

rpm -qa | grep -i java

or

yum list installed | grep java

:white_check_mark: Why it matters?

  • Confirms if Java is installed via RPM.
  • Lets you see the exact version/package details.

:pushpin: Missing Java? No worries:

sudo yum install java-1.8.0-openjdk