ā˜• Java

Java Installation Guide 2026

A complete step-by-step guide to installing Java JDK 21 on Windows, macOS, and Linux — including JAVA_HOME setup, PATH configuration, IDE installation (IntelliJ IDEA, Eclipse, VS Code), and running your first Java program.

šŸ“…

Last Updated

March 2026

ā±ļø

Read Time

20 min

šŸŽÆ

Level

Beginner

Java Installation — Overview

Before you can write and run Java programs on your computer, you need to install the Java Development Kit (JDK). The JDK contains the Java compiler (javac), the Java runtime (java), and all tools needed to develop Java applications. Without the JDK, you cannot compile or run any Java code.

In this chapter, you will set up a complete Java development environment from scratch — covering all three major operating systems: Windows, macOS, and Linux (Ubuntu). By the end, you will have Java installed, your environment configured, and an IDE ready to write your first real Java program.

  • ā–¶

    What you will install: Java JDK 21 LTS + JAVA_HOME + PATH + IDE (IntelliJ IDEA / Eclipse / VS Code)

  • ā–¶

    Time required: 15–30 minutes depending on your internet speed and OS.

  • ā–¶

    Cost: ₹0 — everything in this guide is 100% free and open-source.

What You Need to Install

There are two components you need: the JDK (to write and compile Java) and an IDE (to write code efficiently with syntax highlighting, autocomplete, and debugging). Here is what we recommend in 2026:

ComponentRecommended ChoiceVersionDownload URLCost
JDKEclipse Temurin (OpenJDK)Java 21 LTSadoptium.netFree
JDK (Alternative)Oracle JDKJava 21 LTSoracle.com/javaFree (NFTC)
Primary IDEIntelliJ IDEA CommunityLatestjetbrains.com/ideaFree
Alternative IDEEclipse IDE2025-09 or latereclipse.org/ideFree
Lightweight IDEVS Code + Java PackLatestcode.visualstudio.comFree

Why Eclipse Temurin (OpenJDK)? It is the most popular free OpenJDK distribution, maintained by the Eclipse Foundation, and available for all major platforms with easy installers. It is used by millions of developers and is 100% GPL-licensed open source.

JDK DistributionMaintained byLicenseBest For
Eclipse TemurinEclipse FoundationGPLMost developers — free, reliable, community-backed
Oracle JDK 21OracleNFTC (free)Enterprises already in Oracle ecosystem
Amazon CorrettoAmazon AWSGPLDevelopers deploying on AWS
Microsoft OpenJDKMicrosoftGPLDevelopers on Azure / Windows environments
GraalVM CEOracle LabsGPLAdvanced: native image compilation, polyglot

Step-by-Step: Install Java on Windows

Follow these steps to install Java JDK 21 on Windows 10 or Windows 11. The process takes about 5 minutes.

Step 1 — Download JDK 21

  • ā–¶

    Go to adoptium.net (Eclipse Temurin) or oracle.com/java/technologies/downloads

  • ā–¶

    Select: Version = 21 (LTS) → Operating System = Windows → Architecture = x64

  • ā–¶

    Download the .msi installer file (e.g., OpenJDK21U-jdk_x64_windows_hotspot_21.0.x.msi)

Step 2 — Run the Installer

  • ā–¶

    Double-click the downloaded .msi file to launch the installer wizard.

  • ā–¶

    Click Next → keep the default installation path (C:\Program Files\Eclipse Adoptium\jdk-21.x.x.x-hotspot\) → Click Install.

  • ā–¶

    āœ… Important: On the feature selection screen, make sure "Set JAVA_HOME variable" and "Add to PATH" checkboxes are enabled. The Temurin installer can set these automatically.

  • ā–¶

    Click Finish when installation is complete.

Step 3 — Verify Installation

šŸ’» Command PromptWindows CMD / PowerShell
# Open Command Prompt or PowerShell and run:

java -version
# Expected output:
# openjdk version "21.0.2" 2024-01-16 LTS
# OpenJDK Runtime Environment Temurin-21.0.2+13
# OpenJDK 64-Bit Server VM Temurin-21.0.2+13

javac -version
# Expected output:
# javac 21.0.2

Set JAVA_HOME & PATH on Windows (Manual Method)

If the installer did not set JAVA_HOME automatically, or if you need to switch between multiple JDK versions, here is how to set it manually on Windows.

Method 1 — Using System Properties GUI

  • ā–¶

    Press Win + S → Search "Environment Variables" → Click "Edit the system environment variables"

  • ā–¶

    In the System Properties window → Click "Environment Variables" button

  • ā–¶

    Under System variables → Click "New"

  • ā–¶

    Variable name: JAVA_HOME | Variable value: C:\Program Files\Eclipse Adoptium\jdk-21.0.2.13-hotspot → Click OK

  • ā–¶

    In System variables → Find and select Path → Click "Edit" → Click "New" → Add: %JAVA_HOME%\bin → Click OK on all windows.

  • ā–¶

    Restart Command Prompt (close and reopen) → run java -version to confirm.

Method 2 — Using PowerShell (Admin)

šŸ’» PowerShell (Admin)Set JAVA_HOME via PowerShell
# Run PowerShell as Administrator

[System.Environment]::SetEnvironmentVariable(
  'JAVA_HOME',
  'C:\Program Files\Eclipse Adoptium\jdk-21.0.2.13-hotspot',
  'Machine'
)

[System.Environment]::SetEnvironmentVariable(
  'Path',
  $env:Path + ';%JAVA_HOME%\bin',
  'Machine'
)

# Restart PowerShell, then verify:
echo $env:JAVA_HOME
java -version

Step-by-Step: Install Java on macOS

There are two ways to install Java on macOS — using the .pkg installer (recommended for beginners) or using Homebrew (recommended for developers). Both are covered below.

Method 1 — .pkg Installer (Easiest)

  • ā–¶

    Go to adoptium.net → Version: 21 (LTS) → OS: macOS → Architecture: aarch64 (Apple Silicon M1/M2/M3/M4) or x64 (Intel Mac)

  • ā–¶

    Download the .pkg file → Double-click to run → Follow the installation wizard → Click Install.

  • ā–¶

    The JDK installs to: /Library/Java/JavaVirtualMachines/temurin-21.jdk/

Method 2 — Homebrew (Recommended for Developers)

šŸ’» TerminalmacOS Terminal — Homebrew Install
# Step 1: Install Homebrew (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Step 2: Install Java 21 via Homebrew
brew install --cask temurin@21

# Step 3: Verify
java -version
# openjdk version "21.0.2" 2024-01-16 LTS

javac -version
# javac 21.0.2

Set JAVA_HOME & PATH on macOS

On macOS, environment variables are set in your shell configuration file. The default shell since macOS Catalina is zsh — its config file is ~/.zshrc. Older Macs may use bash (~/.bash_profile).

šŸ’» TerminalSet JAVA_HOME on macOS (zsh)
# Open ~/.zshrc in a text editor:
nano ~/.zshrc

# Add these lines at the bottom of the file:
export JAVA_HOME=$(/usr/libexec/java_home -v 21)
export PATH=$JAVA_HOME/bin:$PATH

# Save and exit nano: Ctrl+O → Enter → Ctrl+X

# Apply the changes immediately:
source ~/.zshrc

# Verify JAVA_HOME is set correctly:
echo $JAVA_HOME
# /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home

java -version
# openjdk version "21.0.2" 2024-01-16 LTS

Pro tip: The macOS command /usr/libexec/java_home -v 21 automatically finds the correct path for the installed JDK 21 — you do not need to hardcode the path. This makes your config portable even after JDK minor version updates.

Step-by-Step: Install Java on Linux (Ubuntu/Debian)

On Ubuntu and Debian-based Linux distributions, Java can be installed via apt package manager — the simplest method — or manually via the .tar.gz from Adoptium.

Method 1 — APT Package Manager (Recommended)

šŸ’» TerminalUbuntu / Debian — APT Install
# Step 1: Update package list
sudo apt update

# Step 2: Install OpenJDK 21
sudo apt install openjdk-21-jdk -y

# Step 3: Verify installation
java -version
# openjdk version "21.0.2" 2024-01-16

javac -version
# javac 21.0.2

# Step 4: Check installation path
which java
# /usr/bin/java

readlink -f $(which java)
# /usr/lib/jvm/java-21-openjdk-amd64/bin/java

Method 2 — Eclipse Temurin via APT Repository

šŸ’» TerminalUbuntu — Temurin via Official Repository
# Step 1: Install required packages
sudo apt install -y wget apt-transport-https

# Step 2: Add Adoptium GPG key
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /etc/apt/trusted.gpg.d/adoptium.asc

# Step 3: Add Adoptium repository
echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list

# Step 4: Update and install Temurin 21
sudo apt update
sudo apt install temurin-21-jdk -y

# Step 5: Verify
java -version
# openjdk version "21.0.2" 2024-01-16 LTS
# OpenJDK Runtime Environment Temurin-21.0.2+13

Managing Multiple Java Versions on Linux

šŸ’» TerminalSwitch Java Version — update-alternatives
# List all installed Java versions:
sudo update-alternatives --list java

# Switch the active Java version interactively:
sudo update-alternatives --config java

# Select the number corresponding to Java 21 → Press Enter

Set JAVA_HOME & PATH on Linux

On Linux, environment variables are set in ~/.bashrc (for bash) or ~/.zshrc (for zsh). Setting JAVA_HOME is required by Maven, Gradle, and many development tools.

šŸ’» TerminalSet JAVA_HOME on Linux (bash/zsh)
# Step 1: Find the exact JDK installation path:
readlink -f $(which java)
# Example output: /usr/lib/jvm/java-21-openjdk-amd64/bin/java
# JAVA_HOME = /usr/lib/jvm/java-21-openjdk-amd64  (remove /bin/java)

# Step 2: Open ~/.bashrc (bash) or ~/.zshrc (zsh):
nano ~/.bashrc

# Step 3: Add these lines at the end of the file:
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

# Step 4: Save & apply changes:
source ~/.bashrc

# Step 5: Verify:
echo $JAVA_HOME
# /usr/lib/jvm/java-21-openjdk-amd64

java -version
# openjdk version "21.0.2" 2024-01-16

Verify Java Installation — All Platforms

After installation, always run these three verification checks to confirm Java is installed and configured correctly on your system — regardless of the operating system.

Verification CommandExpected OutputWhat It Confirms
java -versionopenjdk version "21.0.x" ...JRE/JVM is installed and on PATH
javac -versionjavac 21.0.xJava Compiler (JDK) is installed
echo $JAVA_HOME (Mac/Linux) | echo %JAVA_HOME% (Windows)Path to JDK root directoryJAVA_HOME is set correctly
java -XshowSettings:all -version 2>&1 | grep java.homejava.home = /path/to/jdkActive JVM location (advanced check)
šŸ’» Terminal / CMDQuick Verification Script
# Run all checks at once:

java -version
javac -version

# Mac / Linux:
echo "JAVA_HOME = $JAVA_HOME"

# Windows CMD:
echo JAVA_HOME = %JAVA_HOME%

# Windows PowerShell:
echo "JAVA_HOME = $env:JAVA_HOME"

Output

openjdk version "21.0.2" 2024-01-16 LTS OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13) OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13, mixed mode, sharing) javac 21.0.2 JAVA_HOME = /usr/lib/jvm/java-21-openjdk-amd64

Java IDE — Which One to Choose?

An IDE (Integrated Development Environment) makes writing Java dramatically easier — it provides syntax highlighting, autocomplete, real-time error detection, built-in debugger, project management, and Git integration. While you can write Java in any text editor + terminal, a good IDE can easily 10x your productivity.

IDEBest ForCostPerformanceJava SupportVerdict 2026
IntelliJ IDEA CommunityAll Java developersFreeHeavy but very fast⭐⭐⭐⭐⭐ Excellentāœ… Best Choice
Eclipse IDEEnterprise developersFreeMedium⭐⭐⭐⭐ Very Goodāœ… Great Alternative
VS Code + Java PackLightweight / multi-languageFreeLightweight⭐⭐⭐ Goodāœ… Good for beginners
IntelliJ IDEA UltimateProfessional / Spring BootPaid (~$249/yr)Fast⭐⭐⭐⭐⭐ Bestāœ… Best for pros
NetBeansBeginners / AcademicFreeMedium⭐⭐⭐ Goodāš ļø Less popular in 2026

Our recommendation: Start with IntelliJ IDEA Community Edition — it is free, used professionally, and has excellent Java and Spring Boot support. Once you are comfortable, the Community edition will serve you through your entire Java learning journey.

Install IntelliJ IDEA Community Edition

IntelliJ IDEA by JetBrains is the world's most popular Java IDE. The Community Edition is completely free and covers all Java basics, OOP, Maven, Gradle, and unit testing. Here is how to install it:

  • ā–¶

    Step 1: Go to jetbrains.com/idea/download

  • ā–¶

    Step 2: Choose your OS (Windows / macOS / Linux) → Under Community section → Click Download

  • ā–¶

    Step 3 (Windows): Run the .exe installer → Check "Add to PATH", "Create desktop shortcut", and ".java association" → Click Install.

  • ā–¶

    Step 3 (macOS): Open the .dmg file → Drag IntelliJ IDEA CE to the Applications folder.

  • ā–¶

    Step 3 (Linux): Extract the .tar.gz → Navigate to bin/ → Run ./idea.sh → Optionally create a desktop entry via Tools → Create Desktop Entry.

  • ā–¶

    Step 4: Launch IntelliJ IDEA → Select "Do not import settings" → Choose a theme (Darcula dark or IntelliJ light) → Click Start using IntelliJ IDEA.

Create & Run Your First Java Project in IntelliJ

  • ā–¶

    1. Click "New Project" → Select Java → Set JDK = 21 (IntelliJ auto-detects installed JDK) → Click Next

  • ā–¶

    2. Check "Create project from template" → Select "Command Line App" → Click Next

  • ā–¶

    3. Project name: JavaFirstProject → Base package: com.techsustainify → Click Finish

  • ā–¶

    4. IntelliJ creates a Main.java file → Inside main() method, add: System.out.println("Hello from IntelliJ!");

  • ā–¶

    5. Click the ā–¶ Run button (or press Shift + F10) → See output in the Run panel at the bottom.

ā˜• JavaMain.java — IntelliJ First Run
package com.techsustainify;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello from IntelliJ IDEA!");
        System.out.println("Java " + System.getProperty("java.version") + " is running.");
    }
}

Output

Hello from IntelliJ IDEA! Java 21.0.2 is running.

Install Eclipse IDE for Java

Eclipse IDE is a powerful, free, open-source Java IDE that has been the industry standard in enterprise Java development for decades. It is especially popular in large organizations and academic institutions.

  • ā–¶

    Step 1: Go to eclipse.org/downloads → Click "Download x86_64" to get the Eclipse Installer.

  • ā–¶

    Step 2: Run the Eclipse Installer → Select "Eclipse IDE for Java Developers" from the package list.

  • ā–¶

    Step 3: In the installer: Java JVM → select your JDK 21 installation path → Choose installation folder → Click Install.

  • ā–¶

    Step 4: Accept the license agreement → Wait for installation to complete → Click Launch.

  • ā–¶

    Step 5: Choose a workspace folder (e.g., C:\Users\YourName\eclipse-workspace) → Click Launch.

Create First Java Program in Eclipse

  • ā–¶

    File → New → Java Project → Name: JavaFirstProject → JRE: JavaSE-21 → Finish

  • ā–¶

    Right-click src folder → New → Class → Name: HelloWorld → Check "public static void main" → Finish

  • ā–¶

    Inside main(): add System.out.println("Hello from Eclipse!");

  • ā–¶

    Press Ctrl + F11 (or Run → Run) → Output appears in the Console panel.

Install VS Code for Java Development

Visual Studio Code (VS Code) is a lightweight, fast, free code editor from Microsoft. With the Java Extension Pack, it becomes a capable Java IDE. It is a great choice if you prefer a lighter tool or already use VS Code for other languages.

  • ā–¶

    Step 1: Download VS Code from code.visualstudio.com → Install for your OS.

  • ā–¶

    Step 2: Open VS Code → Press Ctrl + Shift + X to open Extensions panel.

  • ā–¶

    Step 3: Search for "Extension Pack for Java" (by Microsoft) → Click Install. This installs 6 extensions: Language Support for Java, Debugger for Java, Test Runner, Maven, Project Manager, and IntelliCode.

  • ā–¶

    Step 4: VS Code will auto-detect your JDK 21 installation via JAVA_HOME. If not detected: Ctrl + Shift + P → "Java: Configure Java Runtime" → Add JDK path manually.

  • ā–¶

    Step 5: Ctrl + Shift + P → "Java: Create Java Project" → No build tools → Choose a folder → Enter project name → VS Code creates the project structure.

FeatureIntelliJ IDEA CEEclipseVS Code + Java Pack
Setup complexityEasyMediumEasy
RAM usageHigh (~1 GB)MediumLow (~300 MB)
Java autocompleteExcellentVery GoodGood
Built-in debuggerExcellentExcellentGood
Maven / GradleBuilt-inPluginExtension
Spring Boot supportExcellentGoodBasic
Recommended forAll levelsEnterpriseBeginners / Multi-lang devs

Run Your First Java Program — Command Line

Even if you use an IDE, every Java developer should know how to compile and run Java from the command line. This is fundamental knowledge for CI/CD pipelines, servers, and debugging environment issues.

ā˜• JavaHelloWorld.java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Java " + System.getProperty("java.version") + " installed successfully!");
        System.out.println("JDK Home: " + System.getProperty("java.home"));
        System.out.println("OS: " + System.getProperty("os.name"));
        System.out.println("Hello, World! ā˜•");
    }
}

Compile and Run from Terminal / CMD

šŸ’» Terminal / CMDCompile & Run
# Step 1: Navigate to the folder containing HelloWorld.java
cd C:\Users\YourName\JavaProjects   # Windows
cd ~/JavaProjects                     # Mac / Linux

# Step 2: Compile the .java file to .class bytecode
javac HelloWorld.java

# Step 3: Run the compiled .class file
java HelloWorld

# Note: do NOT include .class extension — just the class name

Output

Java 21.0.2 installed successfully! JDK Home: /usr/lib/jvm/java-21-openjdk-amd64 OS: Linux Hello, World! ā˜•

Practice This Code — Live Editor

Common Installation Errors & Fixes

Installation issues are common — especially around PATH and JAVA_HOME configuration. Here are the most frequent errors beginners face and exactly how to fix them.

Error MessageCauseFix
'java' is not recognized as an internal or external commandJava is not added to PATH (Windows)Add %JAVA_HOME%\bin to System PATH → Restart CMD
java: command not foundJava not on PATH (Mac/Linux)Add export PATH=$JAVA_HOME/bin:$PATH to ~/.zshrc or ~/.bashrc → source it
'javac' is not recognized / javac: command not foundJRE installed instead of JDK (no compiler)Uninstall JRE → Install full JDK 21 instead
JAVA_HOME is not setJAVA_HOME environment variable missingSet JAVA_HOME to JDK root directory (not /bin)
error: release version 21 not supportedIDE/Maven using older JDK, not 21Change project SDK to Java 21 in IDE settings
UnsupportedClassVersionErrorCompiled with newer Java, running on older JVMUpdate JVM to match or exceed compile-time Java version
Multiple Java versions conflictOld Java version still active on PATHUse update-alternatives (Linux) or uninstall old version (Windows)

Java Installation — Interview Questions

These questions are commonly asked in Java fresher interviews related to environment setup and Java toolchain knowledge.

Practice Questions — Test Your Knowledge

Test your understanding of Java installation and environment setup with these practice questions.

1. You installed Java but 'java' command gives 'command not found'. What are the two most likely causes?

Easy

2. What is the correct value for JAVA_HOME if Java is installed at C:\Program Files\Java\jdk-21.0.2?

Easy

3. Why does 'javac' command work but 'java' command give an error (or vice versa)?

Medium

4. What is the file extension of compiled Java bytecode? Where is it stored?

Easy

5. On Linux, you have Java 11 and Java 21 installed. How do you switch the active version to Java 21?

Medium

6. What is the difference between 'java HelloWorld' and 'java HelloWorld.class'?

Medium

7. You get 'UnsupportedClassVersionError' when running a .jar file. What does this mean and how do you fix it?

Hard

8. What is the advantage of using IntelliJ IDEA over just a text editor + command line for Java development?

Easy

Conclusion — Your Java Environment is Ready

Congratulations! šŸŽ‰ You have successfully set up your complete Java development environment. Here is a quick summary of everything you have accomplished:

TaskStatus
Downloaded JDK 21 LTS (Eclipse Temurin / Oracle)āœ… Done
Installed JDK on Windows / macOS / Linuxāœ… Done
Set JAVA_HOME environment variableāœ… Done
Added JDK bin to system PATHāœ… Done
Verified: java -version returns 21.xāœ… Done
Verified: javac -version returns 21.xāœ… Done
Installed IDE (IntelliJ IDEA / Eclipse / VS Code)āœ… Done
Created and ran first Java program successfullyāœ… Done

Now that your environment is ready, the next chapter dives into Java Syntax — the fundamental rules for writing correct Java code, covering statements, expressions, operators, and control flow. This is where the real Java learning begins. ā˜•

Tip for beginners: Bookmark the IntelliJ IDEA keyboard shortcuts — Ctrl+Space for autocomplete, Shift+F10 to run, Shift+F9 to debug, and Ctrl+Alt+L to format code. These four shortcuts alone will make you significantly faster as a Java developer.

Frequently Asked Questions (FAQ) — Java Installation