How to Install JDK: A Complete Setup Guide for All Major Platforms
The Java Development Kit (JDK) is the foundational toolkit every Java developer needs. Whether you're writing your first Java program, setting up a build environment, or configuring a server, installing the JDK correctly is the first real step — and getting it wrong creates headaches that echo through your entire workflow.
What the JDK Actually Is (And Why It Matters)
The JDK is more than just "Java." It bundles together:
- The Java compiler (
javac) — converts your.javasource files into bytecode - The Java Runtime Environment (JRE) — executes compiled Java programs
- Development tools like
javadoc,jar, andjdb(the debugger)
Without the JDK, you can run Java applications but not compile or build them. If you only need to run Java software, a JRE alone may suffice. If you're developing, you need the full JDK.
Choosing the Right JDK Version and Distribution
Before downloading anything, there are two decisions to make: which version and which distribution.
JDK Versions
Java follows a release cadence with Long-Term Support (LTS) versions receiving extended maintenance:
| Version | LTS Status | Notes |
|---|---|---|
| Java 8 | LTS | Legacy — widely used in older projects |
| Java 11 | LTS | Common in enterprise environments |
| Java 17 | LTS | Current mainstream choice for new projects |
| Java 21 | LTS | Latest LTS as of recent releases |
| Java 22/23 | Non-LTS | Cutting-edge features, shorter support window |
For most new development, Java 17 or Java 21 is a safe and well-supported starting point.
JDK Distributions
Oracle no longer provides free JDK builds for commercial use in older versions, which led to a healthy ecosystem of free, open alternatives:
- Oracle JDK — official, with licensing restrictions depending on version
- OpenJDK — the open-source reference implementation, free for all uses
- Eclipse Temurin (Adoptium) — popular community-supported OpenJDK builds
- Amazon Corretto — AWS-backed distribution, free and production-ready
- Microsoft Build of OpenJDK — optimized for Azure environments
- GraalVM — adds native image compilation and polyglot capabilities
For general development, OpenJDK or Eclipse Temurin are widely trusted and freely available without licensing complexity.
How to Install the JDK on Windows
- Visit adoptium.net or the OpenJDK site and download the Windows installer (
.msi) for your chosen version. - Run the installer. Accept the license agreement and follow the prompts.
- During installation, ensure "Set JAVA_HOME" and "Add to PATH" options are selected — these are often checkboxes in the installer GUI.
- After installation, open Command Prompt and verify:
java -version javac -versionBoth commands should return the version number you installed.
If the commands aren't recognized, you may need to manually set the JAVA_HOME environment variable and add %JAVA_HOME%in to your system PATH via System Properties → Environment Variables.
How to Install the JDK on macOS 🍎
Option 1 — Using Homebrew (recommended for developers):
brew install openjdk@21 After installation, Homebrew will display a command to symlink the JDK so the system can find it — run that command exactly as shown.
Option 2 — Manual installer: Download the .pkg installer from Adoptium or Oracle, run it, and follow the setup wizard. The JDK installs to /Library/Java/JavaVirtualMachines/.
Verify with:
java -version javac -version On macOS, multiple JDK versions can coexist. Tools like jEnv or SDKMAN! help switch between them when different projects need different Java versions.
How to Install the JDK on Linux
Most Linux distributions can install OpenJDK directly through their package manager:
Ubuntu/Debian:
sudo apt update sudo apt install openjdk-21-jdk Fedora/RHEL:
sudo dnf install java-21-openjdk-devel Arch Linux:
sudo pacman -S jdk-openjdk After installation, verify with java -version and javac -version. On systems with multiple Java versions, use sudo update-alternatives --config java (Debian-based) to set the default.
Setting JAVA_HOME (All Platforms)
Many build tools — Maven, Gradle, Ant, and IDEs — depend on the JAVA_HOME environment variable pointing to the JDK installation directory.
On Linux/macOS, add this to your shell configuration file (.bashrc, .zshrc, etc.):
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java)))) export PATH=$JAVA_HOME/bin:$PATH Then run source ~/.bashrc (or equivalent) to apply changes immediately.
Variables That Affect Your Installation Experience
Even with straightforward steps, several factors shape how this process actually goes for any given developer:
- Operating system version — older macOS or Windows versions may have compatibility quirks with newer JDK releases
- Existing Java installations — having multiple JDKs installed can cause version conflicts if
PATHandJAVA_HOMEaren't set precisely - IDE integration — IntelliJ IDEA, Eclipse, and VS Code each have their own JDK configuration panels that may override system settings
- Build tool requirements — some projects specify a minimum Java version in their
pom.xmlorbuild.gradle, which locks you to a particular JDK - Corporate or containerized environments — Docker images, CI/CD pipelines, and managed enterprise environments often require specific distributions or versions for compliance reasons
- Architecture — Apple Silicon (M1/M2/M3) Macs require ARM64 builds, while most x86 downloads won't apply
The difference between a developer running a solo project on a personal laptop and one configuring a team build server with Java 11 and strict Oracle licensing constraints is significant — the steps may look similar on paper, but the decisions along the way are shaped entirely by context.