JavaInstalling Java

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.

Licensing Has Changed Over the Years
Oracle's licensing terms for its own JDK builds have shifted more than once (notably around Java 11), which is why many teams standardized on free, fully open-source builds like Temurin or Corretto instead. Functionally, these distributions all build from the same OpenJDK source and behave the same way for everyday development — the differences are mostly about support and licensing, not language features.
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:

Bash
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)

Bash
export JAVA_HOME=/usr/lib/jvm/temurin-21-jdk
export PATH=$JAVA_HOME/bin:$PATH

Windows (PowerShell, current session)

Text
$env:JAVA_HOME = "C:\Program Files\Java\jdk-21"
$env:Path = "$env:JAVA_HOME\bin;" + $env:Path
Warning
On Windows and macOS, setting environment variables through a terminal command usually only affects the current session. To make `JAVA_HOME` persist, set it through System Properties (Windows) or your shell profile file such as `.zshrc`/`.bash_profile` (macOS/ Linux), then open a new terminal window.
Tip
Installing multiple JDK versions side by side is common and safe — tools like SDKMAN! (macOS/Linux) or version managers on Windows let you switch the active JDK per project without reinstalling anything.