Check jdk version linux

Java (JRE/JDK) – Check version installed

Firts of all, for end-users, they need to install JRE to run the Java program, and the JDK is for developers. For the production environment, the deployment team only need to install JRE to run the Java program. However, developers often request to install the JDK, instead of the standalone JRE on the production server, because the JDK contains JRE and also extra tools to monitor and debug the running Java program.

The Java development kit (JDK) contains tools for Java development, and the Java Runtime Environment (JRE) contains a JVM to convert byte code .class to machine code, and execute it, in short, the JRE runs Java program.

Check JDK Version

A common way to check JDK version is by using the following simple command to find out the version of the installed JDK. In the below example, the JDK version is 11.0.7:

Check JRE Version

Similarly, we can use java -version to find out the version of the installed JRE. In the below example, the JRE version is 1.8.0_252:

$ java -version openjdk version "1.8.0_252" OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~19.10-b09) OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

The JDK and JRE versions can be different on the same computer. Multiple JDK and JRE versions are allowed on the same computer; it is better to find out which version is configured in the system classpath to run or compile the Java program.

Where JDK is installed?

On Ubuntu or Linux system, we can use which javac to find out where JDK is installed:

$ which javac /usr/bin/javac $ ls -lsah /usr/bin/javac /usr/bin/javac -> /etc/alternatives/javac $ ls -lsah /etc/alternatives/javac /etc/alternatives/javac -> /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/bin/javac $ cd /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/bin/ $ ./javac -version javac 11.0.7

In the above example, the JDK is installed at /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/.

In addition, we can use Linux apt package manager (Debian/Ubuntu systems) to get info about installed Java:

sudo apt list --installed | grep -i openjdk

We can also list all installed packages and filter for Java using the dpkg command:

Читайте также:  Linux как смонтировать образ

And below on RedHat/CentOS systems (obviously the java -version approach is still valid):

rpm -qi openjdk OR yum info "openjdk" OR yum list installed | grep -i openjdk

On Microsoft Windows, we can use dir /b /s javac.exe to find out where JDK is installed.

Microsoft Windows [Version 10.0.18362.900] (c) 2019 Microsoft Corporation. All rights reserved. C:\>dir /b /s javac.exe C:\Program Files\Common Files\Oracle\Java\javapath\javac.exe C:\Program Files\Common Files\Oracle\Java\javapath_target_52887656\javac.exe C:\Program Files\Java\jdk-11.0.12\bin\javac.exe C:\Program Files\Java\jdk1.8.0_271\bin\javac.exe

Or, alternatively, using Powershell:

Get-Childitem –Path C:\ -Include javac.exe -Recurse -ErrorAction SilentlyContinue

Check Java Version in Windows 10 (GUI)

You can get the version number of Java installed on your computer if you enter java in Windows 10 search box and run Java applet.

Java (JRE/JDK) - Check version installed (Classic and Powershell methods)

In About Java window, the current JRE version is specified. In this case, it is Java Version 8 Update 261 (build 1.8.0_261-b12). Note the value of the JRE build. All Java versions have 1 at the beginning followed by the number of major JRE version (it is 8 in this case) and the update number.

Java (JRE/JDK) - Check version installed (Classic and Powershell methods)

We can also check the current Java version in Windows Program and Features (Win+R -> appwiz.cpl).

Java (JRE/JDK) - Check version installed (Classic and Powershell methods)

Check Java Version using PowerShell

You can check Java version installed on your computer using PowerShell. You can just check the version of the executable file java.exe (the path to it is set in the environment variables when JRE SE is installed on your computer). Display the java file version:

Get-Command Java | Select-Object Version

Java (JRE/JDK) - Check version installed (Classic and Powershell methods)

We can view detailed information about Java version, update and release number:

Get-Command java | Select-Object -ExpandProperty Version Major Minor Build Revision ----- ----- ----- -------- 8 0 2610 12

If we want to get a string value of your Java JRE version to be used in scripts, use the command:

(Get-Command java | Select-Object -ExpandProperty Version).tostring()

Java (JRE/JDK) - Check version installed (Classic and Powershell methods)

If we want to specifically be sureabout the JDK version installed on the system, we can use the following Powershell command targeting the Java compiler, javac.exe:

(Get-Command javac | Select-Object -ExpandProperty Version).tostring()

We can also find out your Java version using WMI class Win32_Product (contains the list of installed programs in Windows):

Get-WmiObject -Class Win32_Product -Filter "Name like '%Java%'"

Java (JRE/JDK) - Check version installed (Classic and Powershell methods)

The IDs may be used later to correctly uninstall JRE.

If you want to display only Java version without Java Auto Updater, use the following command:

Get-WmiObject -Class Win32_Product -Filter "Name like '%Java%' and not Name like '%Java Auto Updater%'" | Select -Expand Version

Finally, we can dig directly into the Windows Registry, using Powershell, to get the actual installed version of both JRE and JDK packages with the following two commands:

dir "HKLM:\SOFTWARE\JavaSoft\Java Runtime Environment" | select -ExpandProperty pschildname -Last 1 dir "HKLM:\SOFTWARE\JavaSoft\Java Development Kit" | select -ExpandProperty pschildname -Last 1

Check Java Version on Remote Computers (Powershell)

If we want to get Java versions used on all computers or servers in your domain, you can use the following PowerShell script. The script can get the information from all servers remotely according to the list you enter manually or from a text file. You can also get the list of servers or computers in AD using the Get-ADComputer cmdlet from the RSAT-AD-PowerShell module.

# Check Java version against the list of servers in a text file #$computers=Get-content C:\PS\ServerList.txt # To get Java version on all Windows Servers in AD domain $computers = ((get-adcomputer -Filter < enabled -eq “true” -and OperatingSystem -Like ‘*Windows Server*’ >).name).tostring() Get-WmiObject -Class Win32_Product -ComputerName $computers -Filter “Name like ‘%Java%’ and not Name like ‘%Java Auto Updater%'” | Select __Server, Version

An additional, similar, way to get Java version info from remote systems, by using Powershell, is the following Invoke-Command approach:

$Servers = Get-Content 'C:\Server.txt' $ServersNotAvailable = @() $JavaVersion = < function GetJavaVersion() < Try < $ret = java -version 2>&1 | Select-String "version" | select @>,@> return $ret > Catch < $Prop = [ordered]@New-Object -TypeName psobject -Property $Prop > > GetJavaVersion > foreach($Server in $Servers) < $TestCon = Test-Connection -ComputerName $Server -Count 1 -Quiet if($TestCon) < Invoke-Command -ComputerName $Server -ScriptBlock $javaversion | Select Server,JavaVersion >else < $ServersNotAvailable = $Server + "," + $ServersNotAvailable >> ### Below is list of servers which are not available over the network or not pingable Write-Host "`nServers Not reachable over Network" -ForegroundColor Green $ServersNotAvailable

Источник

Читайте также:  Чем хорош alt linux

How to Check Java Version Installed on Linux

How do I check my current Java version? There are several ways to check if Java is installed and which version is running on your system.

In this tutorial, learn how to check the Java version installed on Linux distros, including Ubuntu, CentOS, and Debian.

tutorial on checking Java version on linux

  • A user account with sudo privileges
  • Access to the command-line/terminal window
  • A version of Java

Method 1: Check the Java Version On Linux

To check the Java version on Linux Ubuntu/Debian/CentOS:

2. Run the following command:

3. The output should display the version of the Java package installed on your system. In the example below, OpenJDK version 11 is installed.

example of checking the version of java running on ubuntu linux

Note: If the output indicates there is no such package on the system, you can install it with the help of one of our guides – How to install Java on Ubuntu or How to Install Java on CentOS.

You can also check the version of the primary Java compiler – javac (pronounced “java-see”) with the command:

Check javac version on Ubuntu.

Method 2: Find Version by Checking Path Where Java is Installed

There are two ways to find the path of the Java directory.

The first option includes running a single command:

update-alternatives --list java

The system should respond with the path where Java is installed.

Check Java directory path to find the java installation version

Note: This option may not work on CentOS systems. If you have issues finding the path of the Java directory with the command above, use the alternative outlined below.

Alternatively, you can use the whereis command and follow the symbolic links to find the Java path.

Читайте также:  Linux mint пакет драйверов

Check Java path on Ubuntu.

The output tells you that Java is located in /usr/bin/java.

2. List the content of the /usr/bin/java directory:

Locate Java directory on Ubuntu.

Inspecting the directory shows that /usr/bin/java is only a symbolic link for /etc/alternatives/java.

3. Just like in the previous step, list the content of the provided path by running:

Find Java path on Ubuntu.

Finally, the output displays /etc/alternatives/java is another symbolic link and that the real path of the Java directory is /usr/lib/jvm/java-11-openjdk-amd64/bin/java.

Method 3: Search for Java in the Installed Packages List

You can also prompt the system to list installed packages and search for Java, with its version number.

Find Java by listing all installed packages.

1. To generate a list of all installed packages, use the command:

2. Scroll up/down until you find the Java packages as shown in this example.

Find Java in the installed packages list.

To avoid searching through all installed packages, list Java packages only. Prompt the system to list a specific software package. In this case, the package name is openjdk:

sudo apt list --installed | grep -i openjdk

Search for Java in the Installed packages list on Ubuntu.

Note: CentOS users need to modify the commands for listing installed packages for their package manager. Use the commands: sudo yum list installed and sudo yum list installed | grep -i openjdk instead.

With this article, you have successfully checked the Java version installed on Linux. We also covered checking the Java path and searching for Java among the installed packages.

Once the Java version is confirmed, you can start developing anything from lightweight mobile to desktop applications.

Источник

Оцените статью
Adblock
detector