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:
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.
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
.msifile 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
# 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.2Set 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 -versionto confirm.
Method 2 ā Using PowerShell (Admin)
# 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 -versionStep-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
.pkgfile ā 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)
# 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.2Set 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).
# 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 LTSPro 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)
# 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/javaMethod 2 ā Eclipse Temurin via APT 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+13Managing Multiple Java Versions on Linux
# 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 EnterSet 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.
# 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-16Verify 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.
# 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-amd64Java 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.
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
.exeinstaller ā Check "Add to PATH", "Create desktop shortcut", and ".java association" ā Click Install. - ā¶
Step 3 (macOS): Open the
.dmgfile ā Drag IntelliJ IDEA CE to the Applications folder. - ā¶
Step 3 (Linux): Extract the
.tar.gzā Navigate tobin/ā 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.javafile ā Insidemain()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.
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(): addSystem.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 + Xto 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.
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.
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
# 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 nameOutput
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.
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?
Easy2. What is the correct value for JAVA_HOME if Java is installed at C:\Program Files\Java\jdk-21.0.2?
Easy3. Why does 'javac' command work but 'java' command give an error (or vice versa)?
Medium4. What is the file extension of compiled Java bytecode? Where is it stored?
Easy5. On Linux, you have Java 11 and Java 21 installed. How do you switch the active version to Java 21?
Medium6. What is the difference between 'java HelloWorld' and 'java HelloWorld.class'?
Medium7. You get 'UnsupportedClassVersionError' when running a .jar file. What does this mean and how do you fix it?
Hard8. What is the advantage of using IntelliJ IDEA over just a text editor + command line for Java development?
EasyConclusion ā 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:
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.