To install Java, download a current Java Development Kit (JDK), run its installer or unpack it with a package manager, make sure java and javac are on your PATH, and confirm with java -version. For new projects, pick a long-term support (LTS) release such as JDK 21 or JDK 25, from a vendor like Oracle, Eclipse Temurin (Adoptium), Amazon Corretto or Microsoft Build of OpenJDK.
You need the JDK, not just the JRE, to compile code. Modern JDK downloads no longer ship a separate JRE, and javac is included in every JDK.
Java releases a new feature version every six months, and some releases are LTS releases with multi-year support. JDK 21 (September 2023) and JDK 25 (September 2025) are LTS releases. Pick an LTS unless a project requires another version.
| Distribution | Notes |
|---|---|
| Eclipse Temurin | Free OpenJDK builds from the Adoptium project |
| Oracle JDK | Oracle's build, free under its current no-fee terms for recent LTS releases; check the licence |
| Amazon Corretto | Free OpenJDK build with long-term updates |
| Microsoft Build of OpenJDK | Free OpenJDK build |
All of them implement the same Java SE specification, so your code runs the same. If a framework or build tool states a required version, follow that requirement.
The simplest route is the package manager that ships with current Windows:
Check the exact package ID in the search output, because IDs change per version. Alternatively, download the .msi installer from the vendor's website, run it and accept the defaults. Many installers offer to set JAVA_HOME and update PATH; enable those options.
With Homebrew:
Or open the .pkg installer downloaded from the vendor. macOS can list installed JDKs and choose one with the java_home tool:
Add the export line to ~/.zshrc, since zsh is the default shell on modern macOS.
Use your distribution's package manager.
Package names depend on the versions your distribution offers, so run apt search openjdk or dnf search openjdk to see the options. If more than one JDK is installed, switch with sudo update-alternatives --config java on Debian-based systems.
SDKMAN works on Linux and macOS and makes switching versions per project easy:
The version identifiers in sdk list java change over time, so copy one from that output.
Most tools, including Maven, Gradle and IDEs, read JAVA_HOME. Package managers usually put java on the PATH, but setting JAVA_HOME helps tools find the right installation.
JAVA_HOME pointing to the JDK folder, for example C:\Program Files\Eclipse Adoptium\jdk-21.0.5.11-hotspot.Path and add %JAVA_HOME%\bin.Add the following to ~/.zshrc or ~/.bashrc, replacing the path with your own:
Then reload the file with source ~/.zshrc or open a new terminal.
Your version numbers will differ. Then compile and run a first program. Since Java 11 you can run a single source file directly, and recent versions simplify the entry point further:
java is not recognised: the bin folder is not on PATH, or you are using a terminal opened before the change.javac is missing: only a runtime was installed. Install the full JDK package, for example the -jdk or -devel package on Linux.PATH. Run which java (Linux and macOS) or where java (Windows) to see which one runs.JAVA_HOME, or configure the toolchain in your build file.Install the JDK if you write Java. It includes the compiler, tools and the runtime. Only install a runtime-only package if you merely run applications.
Choose the latest LTS release your frameworks support, currently JDK 21 or JDK 25. Use a non-LTS release only if you want the newest language features and can upgrade every six months.
OpenJDK builds from Eclipse Temurin, Amazon Corretto and Microsoft are free. Oracle JDK has its own licence terms, so read them before using it commercially.
Yes. Use SDKMAN, update-alternatives, /usr/libexec/java_home or your IDE's JDK settings to select a version per project.
Download a current LTS JDK from a trusted vendor or use winget, Homebrew, apt, dnf or SDKMAN. Set JAVA_HOME, add its bin directory to PATH, and confirm with java -version and javac -version. Keep the JDK updated for security fixes.