Menu

Install Java: Set Up the JDK on Windows, macOS & Linux

How to install the Java Development Kit (JDK), pick a version and vendor, and confirm java and javac work from the command line.

This page includes runnable editors - edit, run, and see output instantly.

What You Actually Need: the JDK

On the previous page you saw that Java compiles to bytecode and runs on the JVM. To do both on your own machine you install one thing: the JDK (Java Development Kit). The JDK bundles the javac compiler, the JVM that runs your bytecode, and the standard library you call into.

You may also hear about the JRE (Java Runtime Environment). The JRE can run a Java program but cannot compile one - it has no javac. As a developer you want the JDK, which is a superset of the JRE. Modern downloads give you the JDK by default, so you rarely have to choose.

You do not need any of this just to follow along with the examples here - the editor blocks on these pages run in the cloud. Install a JDK when you want to compile and run Java on your own computer.

Pick a Version and a Vendor

Two quick decisions before you download.

Version: install the latest LTS (Long-Term Support) release. As of 2026 that is Java 21. LTS versions are supported for years and are what real projects target, so you avoid surprises. Non-LTS releases come out every six months and are fine for experimenting, but LTS is the safe default.

Vendor: "Java" the language has many free distributions, all built from the same OpenJDK source. Any of these is a solid, no-cost choice:

  • Eclipse Temurin (from Adoptium) - the most popular community build.
  • Amazon Corretto - free, long-term supported, by AWS.
  • Azul Zulu - another well-maintained free build.

Pick one, grab the installer for your operating system, and move on. They behave the same for everything in this course.

Avoid the consumer "Java" download from java.com - that is the old end-user JRE, not a JDK. Go to your chosen vendor's developer download page instead.

Install on Your Platform

The mechanics differ slightly per OS. Use a package manager if you have one - it makes upgrades painless.

Windows

  • Download the .msi installer (e.g. Temurin 21) and run it. During setup, enable the option to set JAVA_HOME and add to PATH if offered.
  • Or with the winget package manager:
winget install EclipseAdoptium.Temurin.21.JDK

macOS

  • Download the .pkg installer and run it, or use Homebrew:
brew install temurin

Linux (Debian/Ubuntu)

sudo apt update
sudo apt install openjdk-21-jdk

On Fedora/RHEL it is sudo dnf install java-21-openjdk-devel. These are shell commands, not Java - they install the JDK system-wide.

Verify It Worked

This is the step people skip and then waste an hour on. Open a new terminal (so it picks up the updated PATH) and run two commands.

java -version

You should see something like:

openjdk version "21.0.3" 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode)

Now confirm the compiler is present - this is the part that proves you have the JDK and not just a runtime:

javac -version
javac 21.0.3

If java -version works but javac reports command not found, you installed a JRE-only package or your PATH points at a runtime. Install the JDK package (the names above all end in -jdk or -devel) and reopen the terminal.

A Quick Local Smoke Test

Once both commands report a version, your machine can compile and run Java. The exact same program you will compile locally also runs right here in the browser, so you can sanity-check the output before you ever touch a terminal:

System.getProperty("java.version") asks the running JVM which version it is - a handy way to confirm your install matches what you expect. Every Java program lives inside a class, and execution starts from the main method you see above. On your own machine you would save this as Main.java, compile it with javac, and run it with java. That two-step dance is exactly what the next page covers.

About JAVA_HOME and PATH

Two environment variables come up constantly:

  • PATH tells your shell where to find the java and javac executables. If java -version runs from any directory, your PATH is set correctly. Most installers handle this for you.
  • JAVA_HOME points at the JDK's install folder. You do not need it just to run java, but build tools like Maven and Gradle, and many IDEs, read it to locate your JDK. Set it to the folder that contains the bin directory (not bin itself).

If a tool later complains it cannot find a JDK even though java -version works, an unset or wrong JAVA_HOME is almost always the cause.

Next: Running Java

You have a working JDK and verified the compiler. The next page turns that into a real workflow: writing a .java file, compiling it with javac, running it with java, and understanding what each step produces along the way.

Frequently Asked Questions

Do I need the JDK or the JRE to write Java?

You need the JDK (Java Development Kit). The JRE only runs Java programs - it has the JVM and libraries but no compiler. The JDK includes everything the JRE has plus the javac compiler and developer tools, so it is what you install to write code. Modern downloads ship the JDK; the standalone JRE is mostly gone.

Which Java version should I install?

Install the latest LTS (Long-Term Support) release - Java 21 is the current LTS as of 2026. LTS versions get years of updates and are what most projects target. Grab a free build from Adoptium (Temurin), Amazon Corretto, or Azul Zulu; they are all OpenJDK under the hood.

How do I check if Java is already installed?

Open a terminal and run java -version. If you see a version number, a JVM is installed. Then run javac -version - if that also prints a version, you have the full JDK and can compile. If java works but javac does not, you only have a runtime, so install the JDK.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED