Install Java
Before writing Java code you need a Java installation on your computer. "Installing Java" involves three decisions (what to install, which version, and from which vendor) and one verification step. This lesson explains those decisions; the next lesson walks through installing the JDK on each operating system.
What to Install: the JDK
Java is distributed as the JDK (Java Development Kit). It contains:
javac, the compiler that turns.javasource files into.classbytecodejava, the launcher that starts the JVM and runs programsjshell, an interactive console for trying out codejar,javadoc,jdeps, and other tools- The JVM itself and the complete standard library
For learning and development, always install the JDK. Older guides mention a separate JRE (Java Runtime Environment) for people who only run Java programs. Since Java 11, Oracle and most vendors no longer ship a standalone JRE download; the JDK serves both purposes, and applications that need a minimal runtime build their own with the jlink tool.
Which Version
Java releases a new version every six months (March and September). Every two years one release is designated LTS (Long-Term Support) and receives security updates for several years. Recent LTS versions are 11, 17, 21, and 25.
| Situation | Choose |
|---|---|
| Learning Java, starting a new project | The latest LTS release |
| Working on an existing project | The version the project already uses |
| Experimenting with brand-new language features | The latest feature release |
This tutorial assumes a current LTS (Java 21 or later). Features such as records, text blocks, switch expressions, pattern matching for switch, and virtual threads are not available in older versions, and examples that use them will not compile on Java 8 or 11.
Code written for an older version almost always runs unchanged on a newer JVM, so installing a recent version costs nothing in compatibility for learning purposes.
Which Vendor
All mainstream Java distributions are built from the same open-source codebase, OpenJDK. They behave identically for writing and running programs. The differences are licensing, support options, and update schedules.
| Distribution | Provider | Notes |
|---|---|---|
| Eclipse Temurin | Eclipse Adoptium | Free for any use; a common default choice |
| Oracle OpenJDK builds | Oracle | Free (GPL with Classpath Exception); updated only until the next release |
| Oracle JDK | Oracle | Check Oracle's current license terms before commercial use |
| Amazon Corretto | Amazon | Free, long-term updates; used heavily on AWS |
| Microsoft Build of OpenJDK | Microsoft | Free; used in Azure |
| Azul Zulu | Azul | Free builds plus paid support |
| Red Hat build of OpenJDK | Red Hat | Common on RHEL and Fedora |
For learning, Eclipse Temurin (from adoptium.net) or the OS package manager's OpenJDK package is a safe choice. Any of the distributions listed above will work with every example in this tutorial.
Checking Whether Java Is Already Installed
Open a terminal (Command Prompt or PowerShell on Windows, Terminal on macOS and Linux) and run:
java -version
javac -version
Possible results:
Both commands print a version. A JDK is installed and on your PATH:
openjdk version "25.0.1" 2025-10-21 LTS
OpenJDK Runtime Environment Temurin-25.0.1+8 (build 25.0.1+8-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.1+8 (build 25.0.1+8-LTS, mixed mode, sharing)
javac 25.0.1
The first line names the version. The exact build numbers and vendor text depend on your installation. If the version is 21 or higher, you are ready.
java works but javac is not found. Only a runtime is installed (or the JDK's bin directory is not on the PATH). Install a full JDK.
Neither command is found ('java' is not recognized... on Windows, command not found on macOS/Linux). Java is not installed or is not on the PATH.
The version is old (for example 1.8.0_..., which is Java 8). Install a newer JDK; multiple versions can coexist.
How the Operating System Finds java
When you type java in a terminal, the operating system searches the directories listed in the PATH environment variable, in order, for a program with that name. Installing a JDK puts its programs in a bin folder, for example:
Windows: C:\Program Files\Eclipse Adoptium\jdk-25.0.1.8-hotspot\bin
macOS: /Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home/bin
Linux: /usr/lib/jvm/java-25-openjdk-amd64/bin
Installers and package managers usually add this folder to the PATH for you. If they do not, the commands are installed but cannot be found by name. The next lesson shows how to set PATH and the related JAVA_HOME variable manually.
Multiple versions
Having several JDKs installed is normal for developers who maintain projects on different versions. The one that runs when you type java is whichever appears first on the PATH. Build tools and IDEs can be pointed at a specific JDK regardless of the PATH. Version managers such as SDKMAN! (macOS/Linux) switch between installed JDKs with one command.
To see which java executable is being used:
# macOS / Linux
which java
# Windows
where java
Installation Methods at a Glance
| Method | Platforms | Advantages |
|---|---|---|
Vendor installer (.msi, .pkg) | Windows, macOS | Graphical, can set PATH and JAVA_HOME automatically |
Package manager (winget, brew, apt, dnf) | All | One command, easy updates |
| Version manager (SDKMAN!) | macOS, Linux, WSL | Install and switch between many versions |
Archive (.zip, .tar.gz) | All | No admin rights needed; full manual control |
| IDE-managed download | All | IntelliJ IDEA and others can download a JDK from inside the IDE |
The next lesson gives step-by-step instructions for these methods.
Verifying a Working Setup
After installing, confirm that the whole cycle of writing, compiling, and running works. Create a file named Check.java:
public class Check {
public static void main(String[] args) {
System.out.println("Java version: " + System.getProperty("java.version"));
System.out.println("Vendor: " + System.getProperty("java.vendor"));
System.out.println("Home: " + System.getProperty("java.home"));
}
}
Compile and run it:
javac Check.java
java Check
Example output:
Java version: 25.0.1
Vendor: Eclipse Adoptium
Home: /usr/lib/jvm/temurin-25-jdk-amd64
System.getProperty reads properties that the JVM sets at startup. java.home shows exactly which installation ran the program, which is the quickest way to resolve confusion when several JDKs are installed. If javac produced Check.class without errors and java printed these lines, the installation is complete.
A single-file program can also be run without a separate compile step:
java Check.java
The launcher compiles the file in memory and runs it, which is convenient for small experiments.