Install Java on Windows

Install Java on Windows

Using Chocolatey (Recommended)

# Install Chocolatey if not already installed
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

# Install OpenJDK 17
choco install openjdk --version=17.0.0

# Install OpenJDK 11 if preferred
choco install openjdk --version=11.0.0

Using Scoop

# Install Scoop if not already installed
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex

# Install Java
scoop install openjdk17

Manual Installation

Step 1 - Download Java JDK

Download the Windows x64 Installer from Oracle Java Downloads or get OpenJDK from Adoptium.

Step 2 - Run the Installer

Double-click the .exe file and follow the installation wizard. Note the installation path (usually C:\Program Files\Java\jdk-17).

Step 3 - Set Environment Variables

For Windows 10/11:

  1. Press Windows Key + R, type sysdm.cpl, and press Enter
  2. Go to “Advanced” tab → “Environment Variables”
  3. Under “System variables”, click “New”:
    • Variable name: JAVA_HOME
    • Variable value: C:\Program Files\Java\jdk-17
  4. Find “Path” variable, click “Edit”
  5. Click “New” and add: %JAVA_HOME%\bin

Step 4 - Verify Installation

Open Command Prompt or PowerShell:

java -version
javac -version
echo %JAVA_HOME%
ℹ️
If you see version numbers and JAVA_HOME path, installation was successful!

Command Line Verification

# Check Java version
java -version

# Check compiler version  
javac -version

# Check JAVA_HOME
echo %JAVA_HOME%
Last updated on