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.
- Go to the Oracle Website.
- Select your Operating System (Windows/macOS/Linux).
- Windows Users: Download the
x64 Installer(.exe). - Mac Users: Download the
Arm64 DMG Installer(for M1/M2/M3 chips) orx64(for Intel).
Step 2: Installation
The installation is usually a "Next > Next > Finish" process.
-
Windows: Run the
.exeand note down the installation path (usuallyC:\Program Files\Java\jdk-21). -
Mac: Double-click the
.dmgand 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:
- Search for "Edit the system environment variables" in the Start Menu.
- Click "Environment Variables".
- Under System Variables, click New.
- Variable Name:
JAVA_HOME - Variable Value:
C:\Program Files\Java\jdk-21(Or wherever you installed it).
- Variable Name:
- Find the
Pathvariable, click Edit, then click New. - Type:
%JAVA_HOME%\bin - 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)
Top comments (0)