How To Set JAVA_HOME On Windows 10?

This tutorial shows how to set the JAVA_HOME environment variable on Windows 10 or 11. Setting JAVA_HOME allows tools like Maven, Gradle, and IDEs to find and use your installed Java Development Kit (JDK).

Table of Contents

  • 2. Open Environment Variables
  • 3. Create JAVA_HOME Variable
  • 4. Add JAVA_HOME to PATH
    • 4.1 Older Windows Versions
    • 4.2 Newer Windows 10/11
  • 5. Test JAVA_HOME and Java
  • 6. Why Set JAVA_HOME?
  • 7. References

Technologies Used:

  • Java 21
  • Windows 10/11
1. Open Advanced System Settings

In the Windows search bar (next to the Start button), type advanced system settings, and click View advanced system settings.

advanced system setting

2. Open Environment Variables

In the System Properties window:

  • Go to the Advanced tab
  • Click the Environment Variables… button

environment variables

3. Create JAVA_HOME Variable

In the System variables section:

  • Click the New… button
  • Set the Variable name to JAVA_HOME
  • Set the Variable value to your JDK installation path (do not include the \bin folder)

Example: ✅ C:\Program Files\Java\jdk-21 ❌ C:\Program Files\Java\jdk-21\bin

add java_home

4. Add JAVA_HOME to PATH

To make Java tools accessible from the command line, we must update the PATH variable.

4.1 Older Windows Versions

If you see a single-line text box, append this at the end of the value:

old path edit

4.2 Newer Windows 10/11

If the editor shows a list, click New, and add:

new path add

5. Test JAVA_HOME and Java

Open Command Prompt and run:

java -version javac -version echo %JAVA_HOME% C:\Users\mkyon>java -version openjdk version "21.0.8" 2025-07-15 LTS OpenJDK Runtime Environment Temurin-21.0.8+9 (build 21.0.8+9-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.8+9 (build 21.0.8+9-LTS, mixed mode, sharing) C:\Users\mkyon>javac -version javac 21.0.8 C:\> echo %JAVA_HOME% C:\Program Files\Java\jdk-21

6. Why Set JAVA_HOME?

By setting JAVA_HOME:

  • Java tools (like Maven, Gradle, and IDEs) can locate the JDK easily
  • Java commands like java, javac, jstack, etc., are available system-wide
  • It helps avoid conflicts between multiple Java versions

7. References

  • How to Install Java on Windows (Step-by-Step Guide)
  • How to Set $JAVA_HOME environment variable on macOS
  • How to Open the Control Panel in Windows 10

Từ khóa » Cài đặt Java_home Windows 10