How to Install Java (JDK) on Windows, macOS, and Linux
Step-by-step instructions to download and install the Java Development Kit (JDK) on Windows, macOS, and Linux, and verify the installation.
Before you can write a single line of Java, you need a JDK — the Java Development Kit — installed on your machine. The JDK ships with both the compiler (javac) and the runtime (java), so a single install gives you everything you need to build and run code.
This chapter walks through choosing a distribution, installing it on each major operating system, and verifying that the install works.
Choosing a JDK distribution
Oracle's JDK is not the only option, and these days it's rarely the most convenient one. Several free, open-source builds of OpenJDK are widely used:
- Eclipse Temurin — the default for most teams; ships pre-built binaries for every platform.
- Amazon Corretto — backed by AWS; long-term-supported builds.
- Microsoft Build of OpenJDK — Microsoft-supported builds, well integrated with Azure.
- Azul Zulu — broad version coverage including older releases.
- Oracle JDK — Oracle's own build; free under the No-Fee Terms and Conditions for most uses.
All of them implement the same language and standard library. For this tutorial pick any LTS release — Java 21 if you have a choice, otherwise Java 17.
Install on Windows
- Download the Windows x64 installer (
.msi) for your chosen JDK from the distribution's website. - Double-click the installer and accept the defaults. The installer typically registers
javaandjavacon yourPATHautomatically. - Open a new Command Prompt or PowerShell window (existing terminals won't see the new
PATH). - Run the verification commands below.
If the commands aren't found, you'll need to add the JDK's bin directory to your PATH manually through Settings → System → About → Advanced system settings → Environment Variables.
Install on macOS
The easiest path is Homebrew:
brew install --cask temurin@21Replace 21 with whichever LTS version you want. Homebrew installs the JDK into /Library/Java/JavaVirtualMachines/ and wires it up so java and javac work from any new terminal.
Without Homebrew, download the .pkg installer from the distribution's site and run it. You may need to launch a new terminal afterwards.
Install on Linux
On Debian and Ubuntu:
sudo apt update
sudo apt install openjdk-21-jdkOn Fedora, RHEL, and CentOS Stream:
sudo dnf install java-21-openjdk-develOn Arch:
sudo pacman -S jdk21-openjdkIf you need a specific vendor or version not packaged by your distribution, SDKMAN! is the standard tool for managing multiple JDKs on a single Linux or macOS machine.
Verify the installation
Open a fresh terminal and run:
java -version
javac -versionYou should see output similar to:
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)
javac 21.0.4If both commands print their versions, the JDK is ready. If you see "command not found" (or "java is not recognized…" on Windows), the JDK's bin directory is not on your PATH — re-check the install step or open a new terminal session.
Set JAVA_HOME (optional but common)
Many build tools and IDEs look for an environment variable called JAVA_HOME that points to the JDK install root. Setting it explicitly avoids confusion when you have several JDKs installed.
On macOS and Linux, add the export to your shell profile (~/.zshrc, ~/.bashrc, etc.):
export JAVA_HOME="$(/usr/libexec/java_home -v 21)" # macOS
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk # typical Linux path
export PATH="$JAVA_HOME/bin:$PATH"On Windows, set JAVA_HOME through the Environment Variables dialog and prepend %JAVA_HOME%\bin to PATH.
What's next
With the JDK installed, the next chapter — Setting Up a Java Development Environment — covers IDEs and project structure. After that you'll write and run your first program.
Practice
Which tool does the JDK include that the JRE does not?