There are hundreds of tutorials on installing Java. Most of them tell you to download the JDK from Oracle's website and click Next. In 2026, that advice has quietly become questionable — and almost no article has been updated to say so.
This is the first post in a series on the OCP Java 21 certification. Before talking about the language, you need an environment that works and whose choices you understand. That's what this article covers: installing Java on all three operating systems, knowing why you're installing this version rather than another, and verifying everything works before writing a single line of code.
JRE or JDK: the question that blocks half of all beginners
One mistake comes up constantly: installing the JRE, then wondering why javac doesn't exist.
The JRE (Java Runtime Environment) contains what you need to run an already-compiled Java program: the virtual machine and the standard libraries. It's what the end user of an application needs.
The JDK (Java Development Kit) contains the entire JRE, plus the development tools: the javac compiler, the javap disassembler, the javadoc documentation tool, and the debugger.
To develop — and therefore for this entire series — you need the JDK. If you remember one thing from this section: the JDK contains the JRE, never the other way around.
Why a compiler at all, if Java is portable
This is worth understanding, because it explains the whole toolchain.
Java is neither fully compiled like C, nor interpreted like Python. It sits in between. You write .java source files. The javac compiler turns them into .class files containing bytecode — an intermediate language that no processor understands directly. Then the JVM reads that bytecode and executes it on your machine.
That intermediate step is exactly what makes Java portable: the same .class file runs on Windows, macOS and Linux, because each system has its own JVM. The famous "write once, run anywhere" comes from this design, not from magic.
It also explains why you need the JDK and not just the JRE: without javac, you can run other people's programs, but you cannot turn your own source code into something runnable.
Which version: understanding LTS
Java releases a new version every six months. Most of them are superseded almost immediately. A few are designated LTS (Long-Term Support) and receive security updates for years.
The LTS releases are Java 8, 11, 17, 21 and 25. Java 25 arrived in September 2025, and Oracle now plans an LTS every two years, with Java 29 scheduled for September 2027.
So which one should you install? Java 21, for one specific reason: it is the version the current OCP exam (1Z0-830) is built on. If you're following this series to prepare for that exam, installing Java 25 means studying features the exam won't ask about and, worse, missing behaviour that changed between versions.
If you're here only to learn Java and not for the certification, Java 25 is the better default.
The licensing trap nobody mentions
Here's the part that makes most installation tutorials outdated.
Oracle publishes its own JDK builds, and for a few years, Java 21 was distributed under a permissive licence that allowed free use including in production. That period ended in September 2026. Update releases of Oracle JDK 21 published after that date moved to the Oracle Technology Network licence — the same one that covers Java 8, 11 and 17, which is free for personal and development use, but not for general commercial use.
Oracle's own position is that users who want permissively licensed Java should move to JDK 25 or later.
This puts anyone preparing the Java 21 exam in an awkward spot: you need Java 21, but Oracle's Java 21 is no longer the carefree download it used to be.
The solution is simple, and it's what this series uses: install Eclipse Temurin.
Why Temurin, and what all these distributions actually are
Beginners are often confused by the number of Javas: Oracle JDK, Eclipse Temurin, Amazon Corretto, Azul Zulu, Microsoft Build of OpenJDK. It looks like a fragmented ecosystem. It isn't.
They are all builds of the same source code — the OpenJDK project. What differs is who compiles it, who tests it, who supports it, and under which licence it is distributed. A .class file compiled with Temurin runs identically on Corretto.
For this series, Temurin is the right choice: it's published by the Eclipse Foundation, it's free and open source with no licensing ambiguity, it's available for all three operating systems, and its Java 21 builds will keep receiving updates.
Installing on Linux
On Ubuntu, the simplest route is the distribution's own package:
sudo apt update sudo apt install openjdk-21-jdk If you prefer Temurin's official builds, add the Adoptium repository first:
sudo apt install -y wget apt-transport-https gpg wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list sudo apt update sudo apt install temurin-21-jdk If you end up with several JDKs installed, switch between them with:
sudo update-alternatives --config java sudo update-alternatives --config javac Note that java and javac are configured separately — forgetting the second one is a classic source of version mismatches.
Installing on macOS
With Homebrew:
brew install --cask temurin@21 Without Homebrew, download the installer from adoptium.net/temurin/releases: select version 21 (LTS), macOS, and the right architecture — aarch64 for Apple Silicon (M1 and later), x64 for older Intel Macs. Picking the wrong architecture is the most common macOS mistake.
To set JAVA_HOME, add this to ~/.zshrc:
export JAVA_HOME=$(/usr/libexec/java_home -v 21) The /usr/libexec/java_home utility is macOS-specific and resolves the path for you, which is more reliable than hardcoding it.
Installing on Windows
Download the .msi installer from adoptium.net/temurin/releases: version 21 (LTS), Windows, x64, JDK.
During installation, one screen matters more than all the others. Make sure these options are enabled:
- Add to PATH — so
javaandjavacwork from any terminal - Set JAVA_HOME variable — required by Maven, Gradle and most build tools
If you miss that screen, you'll get javac is not recognized later. You can fix it afterwards through System Properties, Environment Variables, but enabling the checkboxes is far simpler.
If you prefer the command line, winget works too:
winget install EclipseAdoptium.Temurin.21.JDK Verifying the installation
Open a new terminal — an already-open one won't see the updated PATH — and run both commands:
java --version javac --version Both must answer, and both must show version 21. This is where the JRE-versus-JDK confusion surfaces: if java answers but javac says command not found, you have a runtime but no compiler.
Your first program, without an IDE
This series uses Vim on Ubuntu, and the choice is deliberate rather than nostalgic. A modern IDE corrects, completes and hides: it underlines the error before you compile, offers a one-click fix, and sometimes rewrites the line for you. You end up with code that compiles without ever having seen why the other version didn't. For exam preparation, that's exactly backwards.
That said, use whatever you like — Notepad, Notepad++, Nano, VS Code, anything. What matters is that nothing fixes your code for you.
Create a file called Hello.java:
public class Hello { public static void main(String[] args) { System.out.println("Hello from Java 21"); } } Then compile and run it:
javac Hello.java java Hello Notice what happened: javac Hello.java produced a Hello.class file next to your source, and java Hello runs that class — without the extension. Writing java Hello.class is a classic beginner error. The java command takes a class name, not a file name.
The five errors you'll actually hit
javac: command not found — you installed a JRE instead of a JDK, or PATH doesn't include the JDK's bin directory. Check with java --version first: if that works but javac doesn't, it's almost certainly a JRE-only installation.
java: command not found — nothing is installed, or PATH isn't set at all. On Windows, this usually means the "Add to PATH" box wasn't checked.
class file has wrong version 65.0, should be 61.0 — you compiled with a newer JDK than the one running the code. Typically javac points to Java 21 while java points to Java 17. On Linux, fix it with update-alternatives as shown above.
error: class Hello is public, should be declared in a file named Hello.java — your public class name doesn't match the file name. This rule has a real reason behind it, and it's the first thing the next article in this series covers.
Error: Could not find or load main class Hello — you're either in the wrong directory, or you typed java Hello.class instead of java Hello.
What's next
Your environment is ready. The next article starts the book itself, with the chapter everyone skims because it looks easy — and where almost everyone loses points: what a Java source file is actually allowed to contain, and why the main method is far more permissive than you think.
I'm preparing the 1Z0-830 exam with the OCP Java SE 21 Developer Study Guide (Sybex, Jeanne Boyarsky and Scott Selikoff). All explanations and code examples in this article are my own, verified on Ubuntu with JDK 21 and javac on the command line.
Written November 2026. Download links and version numbers change — if something no longer matches, tell me in the comments and I'll update the article.



