Installing Java
To write and run Java programs, you need a JDK (Java Development Kit) installed on your machine. The JDK bundles the compiler (javac), the JVM used to run your programs, and the core libraries every Java program relies on.
JDK vs. JRE — Which One Do You Need?
You may also see the term JRE (Java Runtime Environment). The JRE only contains what’s needed to run already-compiled Java programs — it has no compiler. As a developer, you always want the JDK, since it includes everything the JRE has plus the tools required to actually build software. (Modern JDK downloads include everything you need — you generally don’t install the JRE separately anymore.)
Where to Get a JDK
Distribution | Provider | Notes |
|---|---|---|
Oracle JDK | Oracle | The original, official build. Free to use, with Oracle offering paid long-term support contracts for enterprises. |
Eclipse Temurin (Adoptium) | Eclipse Foundation | A popular free, open-source OpenJDK build with no licensing ambiguity — a common default choice. |
OpenJDK | Community / various vendors | The open-source reference implementation that most other distributions (including Oracle's) are built from. |
Amazon Corretto | Amazon | A free, production-ready OpenJDK build maintained by AWS, with long-term support. |
Installing the JDK
The exact steps vary by operating system, but the general flow is the same everywhere:
Download a JDK build (for example, an LTS release like Java 21) from your chosen provider's website.
Run the installer (Windows/macOS) or use your package manager (Linux — e.g. apt, dnf, or a version manager like SDKMAN!).
Confirm the installation by checking the version from a terminal.
Verifying the Installation
Open a terminal (Command Prompt, PowerShell, or a Unix shell) and run:
java -version javac -version
java version "21.0.3" 2024-04-16 LTS Java(TM) SE Runtime Environment (build 21.0.3+7-LTS-152) Java HotSpot(TM) 64-Bit Server VM (build 21.0.3+7-LTS-152, mixed mode, sharing) javac 21.0.3
If both commands print a version number, the JDK is installed and on your system’s PATH. If you see a “command not found” error, the JDK either isn’t installed or isn’t on your PATH yet.
Setting JAVA_HOME
Many build tools (Maven, Gradle) and IDEs look for an environment variable called JAVA_HOME, which should point to the directory where the JDK is installed (not the bin folder inside it).
macOS / Linux (bash/zsh)
export JAVA_HOME=/usr/lib/jvm/temurin-21-jdk export PATH=$JAVA_HOME/bin:$PATH
Windows (PowerShell, current session)
$env:JAVA_HOME = "C:\Program Files\Java\jdk-21" $env:Path = "$env:JAVA_HOME\bin;" + $env:Path