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
🌐
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.
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
🌐
Linux.org
linux.org › home › forums › general linux forums › general linux topics
Check Java version from Command Line | Linux.org
May 28, 2020 - issues that come up with java usually ... // then hit return/enter button bash-5.0$ // just shows the bash prompt don't type that ... You can use the -version parameter for the java command like below....
🌐
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.
Find elsewhere
🌐
LinuxBuz
linuxbuz.com › linuxhowto › check-java-version-linux
How to Check Java Version On Linux | Ubuntu/Debian/CentOS - LinuxBuz
March 10, 2024 - In the above output, you should see that /usr/bin/java point to symbolic link /etc/alternatives/java. Now, run the ls command again to list the content of /etc/alternatives/java. ... lrwxrwxrwx 1 root root 43 Feb 5 04:50 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java · You can also check the Java version to list installed packages and search for Java.
🌐
Linuxize
linuxize.com › home › java › how to check java version
How to Check Java Version | Linuxize
March 29, 2026 - This command is available on Debian-based distributions (Ubuntu, Debian, Linux Mint). On Fedora and RHEL-based systems, use alternatives --config java instead. Does java -version show the JDK or the JRE?
🌐
Delft Stack
delftstack.com › home › howto › linux › check java version in linux
How to Check Java Version in Linux | Delft Stack
February 2, 2024 - This article discusses the methods to check the version of Java on a Linux machine. To check the Java version in Linux, we can use the version command, the whereis command, and the file path.
🌐
LinuxConfig
linuxconfig.org › home › check java version
How to Check Java Version
June 3, 2020 - Most likely the simplest way is to directly use the java binary in combination with the -version option. To do so run java -version on your terminal. ... Furthermore, execute the following command to check the version of the current default ...
🌐
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 check the Java version on Linux, run the following: ... The output displays the Java package version installed on your system. In the example above, the installed version is OpenJDK 11.0.24. Note: If the output indicates there is no such package on the system, learn how to install Java on Ubuntu · Another way to get the Java version is to check the javac compiler version. Do it with the following command:
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.

🌐
Oracle
java.com › en › download › help › version_manual.html
How to find Java version in Windows or Mac - Manual method
Type the following in a Terminal window: /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version · When launching a Java application through the command line, the system uses the default JDK.
🌐
MTU Service Desk
servicedesk.mtu.edu › TDClient › KB › ArticleDet
Changing Java versions (Linux) - Service Desk
They set the JAVA_HOME profile variable to be retained in all future terminals and shells, but may require you to `source ~/.profile` in order to reload your environment after running the script. source /opt/java-selection/openjdk-java-<version>.bash · source /opt/java-selection/oracle-java-<version>.bash
🌐
Linux Hint
linuxhint.com › check-java-version-linux-ubuntu
How to check Java Version on Linux Ubuntu – Linux Hint
Once this is done, clear the screen and type in the following commands to complete the process of Java home path configuration. ... Given below are certain commands you can use to check your version alongside other important things. ... Press “Y” followed by “ENTER” and the package will be uninstalled. To run Java programs, you’ll need JRE (Java runtime environment). It is compatible with Windows, Linux, Mac, Solaris, and many more.
🌐
TechRepublic
techrepublic.com › home › developer
How To Select Which Version of Java to Use in Linux (+ Video)
March 13, 2024 - This will present you with a list of the different versions of Java you have installed. Each version will be associated with a number, starting with 0. If you want to switch to Java 18, locate and type the associated number for Java 18 and hit Enter on your keyboard. The system will set Java 18 as the current version. You can verify the switch with the following command, where you should see Java 18 listed: ... And that’s all there is to switching between versions of Java on Linux.
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
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - In this tutorial, we’ll see how to switch between multiple Java versions on major Linux distributions. update-java-alternatives is a tool that lets us manage different versions of Java on Debian and Ubuntu. It’s a part of the java-common package: ... $ whereis update-java-alternatives update-java-alternatives: /usr/sbin/update-java-alternatives /usr/share/man/man8/update-java-alternatives.8.gz · Next, we’ll use this command ...
🌐
Itview
itview.in › blog › java › how-to-check-java-version-in-cmd-a-quick-and-easy-guide
How to Check Java Version in CMD: A Quick and Easy Guide
January 23, 2025 - Click OK, and then Restart your Command Prompt. After installation or configuring your environment variables, try the java -version command again.