Edit

Share via


Get started with Java on Windows

This guide covers what's different about setting up Java on Windows compared to Mac or Linux, and gets you to a working JDK installation with your environment configured correctly.

Choose a JDK

Several JDK distributions are available for Windows. Microsoft publishes its own build based on OpenJDK:

For most developers, Microsoft Build of OpenJDK or Temurin are good choices.

Install with winget

Open a PowerShell or Command Prompt terminal and run:

winget install Microsoft.OpenJDK.21

To install Temurin instead:

winget install EclipseAdoptium.Temurin.21.JDK

Verify the installation:

java -version

Set JAVA_HOME

Unlike on macOS (where /usr/libexec/java_home handles this), on Windows you need to set JAVA_HOME manually. Many tools — Maven, Gradle, Android Studio — require it.

  1. Open Start, search for Environment Variables, and select Edit the system environment variables.
  2. Click Environment Variables.
  3. Under System variables, click New and set:
    • Variable name: JAVA_HOME
    • Variable value: the path to your JDK, for example C:\Program Files\Microsoft\jdk-21.0.x.x-hotspot
  4. Find the Path variable under System variables, click Edit, and add %JAVA_HOME%\bin.
  5. Click OK to close all dialogs, then open a new terminal and verify:
echo $env:JAVA_HOME
java -version
javac -version

Tip

If you have multiple JDKs installed, the one listed first in Path takes precedence. Tools like SDKMAN (via WSL) or jEnv can help manage multiple versions.

WSL or native Windows?

For most Java development — web backends, Android, enterprise apps — native Windows works well. Use WSL if your build tooling or deployment target is Linux-specific, or if you're working in a team where everyone else is on Linux/Mac and you want environment parity.

Next steps