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
Discussions

Check Java version from Command Line
I have a Java installation and I have only access via bash. How can I check the Java version from command line. More on community.spiceworks.com
🌐 community.spiceworks.com
6
5
May 28, 2020
linux - How to find which version of Java in Java installed folder? - Unix & Linux Stack Exchange
A version of java is installed on my Linux machine. When i try this: root@test$: javac -version It given the result as: javac jdk1.7.0_80. Now my problem is i don't know where that(1.7.0_80) ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
January 4, 2016
"java: command not found" even though java is installed and in /bin

Check if perhaps 'java' is a script for an interpreter that's not installed, or if it's compiled for the wrong architecture.

More on reddit.com
🌐 r/slackware
17
3
May 17, 2017
Trying (and failing) to run cURL command in JAVA using ProcessBuilder
You aren't doing anything with the output, so while it may be working fine there's no way to tell. You need to store the output in a variable to use it or redirect it to stdout if you just want to have it printed to the console. Also remove the quotes. They are needed for a shell to interpret the input correctly but you are launching the process directly and not going through a shell. This means that the quotes are being part of the url curl is trying to access. More on reddit.com
🌐 r/javahelp
7
5
October 10, 2017
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.
🌐
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.
Find elsewhere
🌐
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?
🌐
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.
🌐
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 ...
🌐
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.
🌐
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.

🌐
LinuxVox
linuxvox.com › blog › see-java-version-linux
Checking Java Version on Linux — linuxvox.com
This is managed through environment variables and the alternatives system in some Linux distributions. The most straightforward way to check the Java version is by using the java -version command in the terminal.
🌐
MTU Service Desk
servicedesk.mtu.edu › TDClient › KB › ArticleDet
Changing Java versions (Linux) - Service Desk
In order to activate a Java version, run the script corresponding to the version you would like to work with, then reload or resource your terminal: For example the following command activates OpenJDK Java 8: `source /opt/java-selection/openjdk-java-8.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.
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 ...
🌐
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.
🌐
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.
🌐
Linux Hint
linuxhint.com › change-java-version-linux
How to Change Java Version Linux – Linux Hint
To demonstrate how we switch between the Java versions, let’s quickly install Java 19. If we check the available Java versions, we now have Java 19 which is the currently set version, and an alternative version which is Java 17. To change the Java version in Linux, use the –config java option ...