General • Beginner • 6 min read

Install Java Development Kit (JDK) and Set Up JAVA_HOME

Summary

Step-by-step procedure to install OpenJDK, configure the JAVA_HOME system environment variable, and verify paths on Windows and Linux.

Companion Tool
JSON Formatter, Validator & Minifier

Free online JSON formatter, beautifier, and validator. Inspect syntax errors, clean ugly payloads, minify JSON strings, and format with custom indentations.

Open tool

Overview

The Java Development Kit (JDK) is the core software development environment required to build Java applications, applets, and microservices. It includes:

  • The Java Compiler (javac): Compiles high-level Java source files (.java) into bytecode (.class).
  • The Java Runtime Environment (JRE / java): Provides the Java Virtual Machine (JVM) and runtime libraries to execute compiled bytecode.
  • Development Utilities: Archiving tools (jar), diagnostic debuggers (jdb), and profiling utilities.

For general software engineering, OpenJDK distributions (such as Eclipse Temurin by Adoptium, Amazon Corretto, or Microsoft Build of OpenJDK) are free, open-source, and unrestricted for commercial use.


Step 1: Downloading Eclipse Temurin (OpenJDK LTS)

  1. Navigate to the official Adoptium portal: adoptium.net.
  2. Select the latest LTS Release (e.g., Java 21 LTS or Java 17 LTS).
  3. Download the 64-bit Windows Installer (.msi).

Alternatively, using Windows Package Manager (winget):

winget install EclipseAdoptium.Temurin.21.JDK

Step 2: Running the Installer and Configuring Features

When running the .msi wizard, inspect the Custom Setup options:

  1. Ensure Set JAVA_HOME variable is selected and set to “Will be installed on local hard drive”.
  2. Ensure Add to PATH is checked.
  3. Finish the installation.

Step 3: Setting JAVA_HOME Manually (If Required)

If you installed the JDK from an unzipped archive or need to manually configure the environment variable:

  1. Press Win + S, type Environment Variables, and choose Edit the system environment variables.
  2. Click the Environment Variables… button at the bottom right.
  3. Under System Variables, click New…:
    • Variable name: JAVA_HOME
    • Variable value: C:\Program Files\Eclipse Adoptium\jdk-21.0.x-hotspot\ (Enter the directory where bin\javac.exe resides).
  4. Locate the Path variable under System Variables, select it, and click Edit….
  5. Click New and add:
    %JAVA_HOME%\bin
  6. Click OK on all dialog boxes to persist the configuration.

Step 4: Verification of Java and Compiler

Open a brand new command prompt or PowerShell window (to load updated environment variables) and verify:

java -version
javac -version

Expected output:

openjdk version "21.0.5" 2024-10-15 LTS
OpenJDK Runtime Environment Temurin-21.0.5+11 (build 21.0.5+11-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.5+11 (build 21.0.5+11-LTS, mixed mode, sharing)
javac 21.0.5

Verify the JAVA_HOME path in PowerShell:

$env:JAVA_HOME

Step 5: Compiling and Running a Test Program

Create a quick test file to confirm proper compilation:

New-Item -Name "Hello.java" -Value 'public class Hello { public static void main(String[] args) { System.out.println("Java Environment Configured Successfully"); } }'

Compile and run:

javac Hello.java
java Hello

Output:

Java Environment Configured Successfully

Related reference