DEV Community

Cover image for The Ultimate Java Setup Guide (2025): Install JDK on Windows, Mac & Linux
SRF DEVELOPER
SRF DEVELOPER

Posted on • Originally published at srfdeveloper.com

The Ultimate Java Setup Guide (2025): Install JDK on Windows, Mac & Linux

This article is Chapter 3 of the Free Java Course. It was originally published on SRF Developer.


You cannot write a single line of Java code without the JDK (Java Development Kit).

Many beginners get stuck right here. They download "Java," try to run a command, and get the dreaded error:
'javac' is not recognized as an internal or external command.

In this guide, I will walk you through the correct way to set up your environment for Windows, Mac, and Linux, and how to fix the Environment Variable issues.

JDK vs JRE: What's the difference?

Before we install, you need to download the right thing.

  • JRE (Java Runtime Environment): Lets you run Java apps (like Minecraft).
  • JDK (Java Development Kit): Lets you write and compile Java apps.

As a developer, you always need the JDK.

Step 1: Download the JDK

For 2025, I recommend JDK 21 (LTS) as it is the current Long Term Support version used by most companies.

  1. Go to the Oracle Website.
  2. Select your Operating System (Windows/macOS/Linux).
  3. Windows Users: Download the x64 Installer (.exe).
  4. Mac Users: Download the Arm64 DMG Installer (for M1/M2/M3 chips) or x64 (for Intel).

Step 2: Installation

The installation is usually a "Next > Next > Finish" process.

  • Windows: Run the .exe and note down the installation path (usually C:\Program Files\Java\jdk-21).
  • Mac: Double-click the .dmg and follow the prompts.

Step 3: The Critical Step (Environment Variables) ⚠️

This is where 90% of beginners fail. If you don't do this, your terminal won't know where Java is.

For Windows Users:

  1. Search for "Edit the system environment variables" in the Start Menu.
  2. Click "Environment Variables".
  3. Under System Variables, click New.
    • Variable Name: JAVA_HOME
    • Variable Value: C:\Program Files\Java\jdk-21 (Or wherever you installed it).
  4. Find the Path variable, click Edit, then click New.
  5. Type: %JAVA_HOME%\bin
  6. Click OK on everything.

For Mac/Linux Users:

You need to update your shell configuration (.zshrc or .bashrc).

Open your terminal and run:


bash
echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> ~/.zshrc
source ~/.zshrc

Step 4: Verify Installation
Close any open terminals/command prompts and open a new one. Type:
java -version

If you see java version "21.0.x", congratulations! You are ready to code.

​Next Steps

​Now that your environment is ready, it's time to write your first "Hello World" program.

​Need visual help? I have created a guide for every single step (including how to verify the Path) on the full blog post.
​👉 [Click here to read the Full Visual Guide on SRF Developer](https://www.srfdeveloper.com/2025/11/chapter-3-how-to-install-java-jdk-windows-mac-linux.html)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)