How-To Guide
How to Install Java
Java powers Android apps, enterprise backends, and Minecraft servers. Here's how to install the JDK on any operating system in about 10 minutes.
📋 What You'll Need
- A computer running Windows, macOS, or Linux
- An internet connection
- About 300 MB of free disk space
- 10 minutes of your time
✅ Java (OpenJDK) is completely free. No credit card, no signup.
🧩 JDK vs JRE vs JVM — What Do You Need?
- JVM — runs compiled Java code (the engine)
- JRE — JVM + libraries (enough to run Java apps)
- JDK — JRE + compiler (needed to write Java code)
If you're learning or building, install the JDK.
Download the JDK
Go to the official OpenJDK distribution site:
👉 adoptium.net
Click Latest LTS Release and download the installer for your OS. Install Java 21 LTS — it's supported until 2031 and works with all modern tools.
- Windows: .msi installer (x64)
- Mac: .pkg installer (Intel or Apple Silicon)
- Linux: .deb, .rpm, or use your package manager
Run the Installer
Windows:
- Open the downloaded
.msifile - Click "Next" through the wizard
- On "Custom Setup", enable "Set JAVA_HOME variable" and "Add to PATH"
- Click "Install" → "Finish"
Mac:
- Open the downloaded
.pkgfile - Follow the installer wizard
- Or via Homebrew:
brew install openjdk@21
Linux (Ubuntu/Debian):
sudo apt update
sudo apt install openjdk-21-jdk
Verify the Installation
Open a terminal (Command Prompt, Terminal, or PowerShell) and run:
java --version
javac --version
You should see version numbers like openjdk 21.0.1. If both commands work, Java is installed correctly.
Test with Hello World
Create a file called Hello.java:
public class Hello {
public static void main(String[] args) {
System.out.println("Java is working!");
}
}
Compile and run it:
javac Hello.java
java Hello
You should see Java is working! printed. 🎉
💡 How Java works: javac compiles your source code into bytecode (Hello.class). Then java runs that bytecode on the JVM. That's the two-step process.
⚙️ Setting JAVA_HOME (If Needed)
Some tools (Maven, Gradle, Android Studio) look for a JAVA_HOME environment variable. Set it only if a tool asks for it.
macOS / Linux — add to ~/.zshrc or ~/.bashrc:
export JAVA_HOME=$(/usr/libexec/java_home -v 21)
export PATH=$JAVA_HOME/bin:$PATH
Windows PowerShell:
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Eclipse Adoptium\jdk-21.0.1.12-hotspot", "Machine")
🔧 Troubleshooting
"java: command not found"
Your PATH doesn't include Java's bin folder. Restart your terminal. On macOS/Linux, check that JAVA_HOME is exported correctly.
"javac: command not found" (but java works)
You installed the JRE instead of the JDK. The JRE runs Java apps but can't compile them. Uninstall it and install the JDK.
Multiple Java versions installed
Run java --version to see which is active. On macOS use /usr/libexec/java_home -V to list all. On Linux use update-alternatives --config java.
🎯 What's Next?
Now that you have Java installed, you're ready to start building: