On most Linux distributions you can use update-alternatives like this:

sudo update-alternatives --config java

It will list all packages that provide java command and will let you change it. If you don't want to change it, simply Ctrl-C from it.

There is only one catch - if you installed some java not using official package manager (dpkg/apt-get, rpm/yum), but simply extracted it, update-alternatives will not show it.

Answer from mvp on Stack Exchange
Top answer
1 of 5
19

update-java-alternatives -l will list all the java versions installed via the alternatives system.

For instance on one of my systems it will display the version and the path:

java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64
java-7-oracle 1069 /usr/lib/jvm/java-7-oracle

If you want the oracle one then I guess you could do:

update-java-alternatives -l | grep oracle | awk '{ print $1 }'

This would alternatively find all oracle versions and issue the -version command against each one in the list:

update-java-alternatives -l | grep oracle | awk '{system($3"/bin/java -version")}'

Output may look something like this:

java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

One step further would be to parse out the java version from the -version command and simply display it:

(update-java-alternatives -l | grep oracle | awk '{system(""$3"/bin/java -version 2>&1 | grep \"java version\"")}') | awk -F\" '{print $2}'

The 2>&1 is needed because Java will display version to standard error. The output would simply look like this (and could be easily assigned to a bash variable if you needed it that way):

1.7.0_67

If you had multiple oracle instances this would display the version for each one. If you wanted to find all the versions for every Java you could simply remove the | grep oracle

2 of 5
8

If you are using the openjdk java, then the oracle Java in your PC is just a folder. There is no command to check the version of that if you are not using it.

If you once used oracle java then it must be in your java alternatives and you can find the folder (usually with version in name) with:

update-alternatives --config java

If it says something like /usr/lib/jvm/jdk1.8.0_05/bin/java, then you have 1.8 in your pc.

If you haven't used oracle java anytime you simply have to check what you have downloaded.

If you want to simply see the version you are using:

java -version

Hope it helps

People also ask

Does `java -version` show the JDK or the JRE?
It shows whichever runtime is set as the default. Both the JRE-only package and the full JDK include the `java` command. To confirm that the JDK is installed, check for `javac` as described above.
🌐
linuxize.com
linuxize.com › home › java › how to check java version
How to Check Java Version | Linuxize
How do I check the Java version inside a shell script?
Parse the output of `java -version`, which prints to standard error: ```bash java -version 2>&1 | head -n 1 | awk -F '"' '{print $2}' ``` This returns a string such as `21.0.4` that you can compare in your script.
🌐
linuxize.com
linuxize.com › home › java › how to check java version
How to Check Java Version | Linuxize
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to check java version installed on linux
How to Check Java Version Installed on Linux
December 11, 2025 - To avoid searching through all installed packages, list Java packages only. Prompt the system to list Java packages by searching for openjdk with grep: ... This article explained how to check the Java version on Linux using three different methods.
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › how-to-check-java-version-in-linux
How to Check Java Version in Linux - GeeksforGeeks
July 23, 2025 - From the output of the command sudo apt list --installed | grep -i openjdk, you can confirm that the OpenJDK version installed is 11.0.19. This version is part of the Ubuntu 18.04 (bionic) updates and security patches.
🌐
Linuxize
linuxize.com › home › java › how to check java version
How to Check Java Version | Linuxize
March 29, 2026 - Find out which Java version is installed on your system, check the JDK compiler version, and manage multiple Java installations from the command line.
Top answer
1 of 4
121

The simplest way is:

update-java-alternatives -l shows you all the Java versions you have installed.

java -version shows you the Java version you are using.

java -showversion shows you the Java version you are using and help.

Normally it would be OpenJDK.

2 of 4
43

This command should tell you what is currently providing the Java virtual machine (java) and the Java compiler (javac):

file /etc/alternatives/java /etc/alternatives/javac

This assumes the "alternatives" system is working properly, which might not be the case, depending on how Java has been "messed up" in the past. To check this, run:

file `which java javac`

If the alternatives system is working correctly and being used by Java, then you should see:

/usr/bin/java:  symbolic link to `/etc/alternatives/java'
/usr/bin/javac: symbolic link to `/etc/alternatives/javac'

Otherwise please edit your question to provide details. Then it should be possible to give a more specific answer.


You can remove openjdk-6 with the Software Center. There are multiple packages associated with it, so you may need to remove more than one packages. (All the `openjdk-6 packages are listed here.)

Or you can use the command-line:

sudo apt-get remove openjdk-6-\* icedtea-6-\*

However, whichever method you use, you may want to check first to see what depends on these packages--you might have software installed that specifically needs version 6. (Probably not, but possibly.)

You can check for this by simulating the removal operation on the command-line:

apt-get -s remove openjdk-6-\* icedtea-6-\*

This will show you the effects of removing those packages, including what other packages would be removed as well. (You'll notice that since this is a simulation, you don't need sudo.)

If you want to be able to continue using Java content online in your web browser (this is not the same thing as JavaScript), then before you remove any icedtea-6- or openjdk-6- packages (except perhaps openjdk-6-jdk), you should make sure you have icedtea-7- packages installed corresponding to whatever icedtea-6- packages are installed.

🌐
LinuxBuz
linuxbuz.com › linuxhowto › check-java-version-linux
How to Check Java Version On Linux | Ubuntu/Debian/CentOS - LinuxBuz
March 10, 2024 - You can use yum or dnf command to list all installed packages and search for Java as shown below: ... java-11-openjdk.x86_64 1:11.0.9.11-3.el8_3 @AppStream java-11-openjdk-devel.x86_64 1:11.0.9.11-3.el8_3 @AppStream java-11-openjdk-headless.x86_64 ...
Find elsewhere
🌐
Edureka Community
edureka.co › home › community › categories › java › how to check java version in linux
How to check java version in linux | Edureka Community
October 27, 2023 - What are the steps to determine the version of Java installed on a Linux system, and how ... the detected version is correctly configured for use?
🌐
LinuxVox
linuxvox.com › blog › how-to-check-java-version
How to Check Java Version: A Comprehensive Guide — linuxvox.com
To list all installed versions: Windows: Check C:\Program Files\Java\ (folders like jdk-17.0.9, jre1.8.0_381). ... Linux: Use update-alternatives --config java (Debian/Ubuntu) to switch versions.
🌐
VITUX
vitux.com › verify-java-installation-on-ubuntu-and-check-the-installed-version-if-any
Verify JAVA Installation on Ubuntu and Check the Installed version (if any) – VITUX
If you have any version of Java installed on your system, the output will display Java OpenJDK and JRE version information as follows: Enter the following command to check the directory in which Java is installed: ... However, if Java is installed on your system, this command will show the exact path where Java is installed: You can check if a software package is installed on your system by using the following command syntax: ... This command will list all the JDK packages available in the Ubuntu repositories.
🌐
LinuxConfig
linuxconfig.org › home › check java version
How to Check Java Version
June 3, 2020 - There are several ways on how to check what version of Java is installed on your system. Most likely the simplest way is to directly use the java binary in combination with the -version option.
🌐
Scaler
scaler.com › home › topics › how to check java version in linux?
How to Check Java Version in Linux? - Scaler Topics
July 19, 2023 - Step 3: Install Java: Use the following command to install Java on your Linux system: Step 4: Verify the installation: After the installation process completes, you can verify it by running the java -version command again.
🌐
Oracle
java.com › en › download › help › version_manual.html
How to find Java version in Windows or Mac - Manual method
There can be multiple JDKs installed on a system, as many as you wish. Type the following in a Terminal window: /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
Top answer
1 of 3
7

I think you can track all this by checking to where your java binaries linked to.

       #which javac
          /usr/bin/javac   
       #ls -ln /usr/bin/java
           lrwxrwxrwx. 1 0 0 22 Nov 27 04:54 /usr/bin/java -> /etc/alternatives/java
       #ls -ln /usr/bin/javac
            lrwxrwxrwx. 1 0 0 23 Nov 27 04:54 /usr/bin/javac -> /etc/alternatives/javac
       # ls -ln /usr/bin/javadoc
            lrwxrwxrwx. 1 0 0 25 Nov 27 04:54 /usr/bin/javadoc -> /etc/alternatives/javadoc

and finally:

#ls -ld /etc/alternatives/java
lrwxrwxrwx. 1 root root 46 Nov 27 04:54 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java

therefore , my java installation is:

   /usr/lib/jvm/jre-1.7.0-openjdk.x86_64

I suppose you can track any binary like this.

2 of 3
5

Finding out which binary is executed when you type only the name is done using which, and using readlink you can condense the process to a single line.

readlink -e $(which java)

readlink -e prints the value of a symbolic link or canonical file name, and the -e ensures it follows every component recursively.

tony@trinity:~$ readlink -e $(which java)
/usr/lib/jvm/java-6-openjdk-i386/jre/bin/java

note: I don't have javac installed on the machine I tested this on, so just used java, but the above will work work for any binary.

You also appear to be asking to find out which version of java is in a specific folder? For that you just do this,

/full/path/java -version

which prevents Linux from search the path and finding the java binary directly. In your case,

/usr/lib/jvm/java-7-oracle/javac -version
🌐
Stack Overflow
stackoverflow.com › questions › 44393550 › find-all-java-versions-in-the-system-path
linux - Find all Java versions in the system path - Stack Overflow
which -a python | xargs -I{} echo "echo {};{} --version;echo" | sh ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Without foundational governance, every AI deployment is a liability in... ... Can gaming set proficiency replace multiple skill checks in the D&D 5e Gambling downtime activity from Xanathar's Guide to Everything? ... What's the difference between federal income tax and payroll tax? Are y'all taxed twice on your pay?
🌐
idroot
idroot.us › home › how to check java version installed on linux
How to Check Java Version Installed on Linux - idroot
March 26, 2025 - This interactive command presents available Java versions, allowing you to select which one should be the system default. Package managers maintain detailed records of installed software, providing another source of information about your Java installations. ... Understanding exactly where Java resides on your filesystem helps with troubleshooting and configuration. ... This returns the path to the Java binary that executes when you type java at the command line. ... On most Linux systems, the path returned by which java is actually a symbolic link.
🌐
Codegrepper
codegrepper.com › code-examples › java › linux+command+to+see+all+the+java+version+installed
linux command to see all the java version installed Code Example
May 28, 2020 - All Languages >> Java >> linux command to see all the java version installed · Search · 75 · Loose MatchExact Match · 2 Code Answers · Sort: Best Match ↓ · Best Match · Relevance · Date · Quality Score · Views · Up Votes · java by Bright Butterfly on May 28 2020 Comment · 2 · Source: superuser.com · java by Bright Butterfly on May 28 2020 Comment · 0 · Source: superuser.com · Add a Grepper Answer · java version command · check java version linux ·