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 - In your linux command terminal, type the following java command and press Enter: ... This command will display the Java version installed on your system. The output will include details such as the version number, runtime environment, and build. Here is how you can check java version with the help of directory path, run the following command:
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
🌐
Linuxize
linuxize.com › home › java › how to check java version
How to Check Java Version | Linuxize
March 29, 2026 - On Fedora and RHEL-based systems, use alternatives --config java instead. 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.
🌐
LinuxBuz
linuxbuz.com › linuxhowto › check-java-version-linux
How to Check Java Version On Linux | Ubuntu/Debian/CentOS - LinuxBuz
March 10, 2024 - In this post, we will show you different methods for how to check Java version on Ubuntu, Debian and CentOS operating system.
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.

Find elsewhere
🌐
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.
🌐
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.
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

🌐
Javatpoint
javatpoint.com › how-to-find-the-java-version-in-linux
How to Find the Java Version in Linux - Javatpoint
How to Find the Java Version in Linux with java tutorial, features, history, variables, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
LinuxConfig
linuxconfig.org › home › check java version
How to Check Java Version
June 3, 2020 - To do so run java -version on your terminal. ... Furthermore, execute the following command to check the version of the current default Java compiler javac:
🌐
LinuxVox
linuxvox.com › blog › check-java-version-linux
Checking Java Version on Linux: A Comprehensive Guide — linuxvox.com
Linux uses the alternatives system to manage multiple installations of the same type of software. The most straightforward way to check the Java version is by using the java -version command.
🌐
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.
🌐
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 - 258133/how-to-check-java-version-in-linux · Home · Community · Categories · Java · How to check java version in linux · how do I turn a double in an array from 1000 to infinity Jul 9, 2024 · I have created a code in java for a flower shop and now my IDE is showing all the inputs are in red showing there is an error Jul 6, 2024 ·
🌐
Linux Hint
linuxhint.com › check-java-version-linux-ubuntu
How to check Java Version on Linux Ubuntu – Linux Hint
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.
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › reference › availability › java
Available Java versions - Ubuntu for Developers
1 day ago - This page lists Java versions available in Ubuntu releases, including CRaC and GraalVM. Ubuntu OpenJDK (deb) packages:,,, Ubuntu version, available Java versions, java-common version,,, 26.10 (Ston...
🌐
idroot
idroot.us › home › how to check java version installed on linux
How to Check Java Version Installed on Linux - idroot
March 26, 2025 - All techniques require terminal access to your Linux system. Access the terminal through your desktop environment’s application menu or by pressing key combinations like Ctrl+Alt+T on many distributions. ... JRE vs. JDK Distinction · It’s important to understand the difference between: Java Runtime Environment (JRE): Contains everything needed to run Java applications · Java Development Kit (JDK): Includes the JRE plus development tools for Java programming · The version-checking methods may reveal which component you have installed, as they report slightly different information.
🌐
LinuxVox
linuxvox.com › blog › how-to-check-java-version
How to Check Java Version: A Comprehensive Guide — linuxvox.com
In the Java Control Panel, go to General > About to view the version. Linux distributions (e.g., Ubuntu, Fedora, CentOS) use the terminal for most system tasks, including checking Java version.