How to Install Java on Windows, Mac, and Linux

Java remains one of the most widely used programming platforms in the world — powering everything from enterprise software to Android apps to web-based tools. Whether you're a developer setting up a new machine, a student following a course, or someone prompted to install Java to run a specific application, the process varies more than most people expect.

Here's a clear breakdown of how Java installation works, what decisions you'll encounter, and what factors shape the right approach for different setups.

What You're Actually Installing

Before you download anything, it helps to understand what "Java" means in this context. There are two distinct things:

  • JRE (Java Runtime Environment): What you need to run Java-based applications. If someone just told you to "install Java" to use a specific program, this is usually what they mean.
  • JDK (Java Development Kit): What you need to write and compile Java code. It includes the JRE plus development tools like the compiler (javac).

There's also the question of which Java. Oracle's official JDK is the most widely known, but OpenJDK is a free, open-source alternative that many developers prefer. Distributions like Amazon Corretto, Eclipse Temurin (Adoptium), and Microsoft Build of OpenJDK are all based on OpenJDK and are used widely in production environments.

Installing Java on Windows

  1. Go to the official source. For Oracle's JDK, visit oracle.com. For OpenJDK builds, adoptium.net (Eclipse Temurin) is a reliable choice.
  2. Choose your version. Java versions follow a release cycle. LTS (Long-Term Support) versions — such as Java 11, 17, and 21 — are generally recommended for stability. Non-LTS versions receive shorter support windows.
  3. Download the installer. Select the Windows .exe or .msi installer for your architecture (x64 for most modern systems).
  4. Run the installer. Follow the prompts. The installer will handle placing files in the right directories.
  5. Set the JAVA_HOME environment variable. This step is optional for basic use but often required for development tools. In Windows, go to System Properties → Advanced → Environment Variables, add a new system variable named JAVA_HOME, and set its value to the Java installation path (e.g., C:Program FilesJavajdk-21). Add %JAVA_HOME%in to your PATH variable as well.
  6. Verify the installation. Open Command Prompt and run:
    java -version 

    You should see the installed version number printed back.

Installing Java on macOS 🍎

macOS no longer ships with Java pre-installed. Your options:

  • Manual download: Grab the .dmg installer from Oracle or a trusted OpenJDK distributor. Run it, and Java installs into /Library/Java/JavaVirtualMachines/.
  • Homebrew (recommended for developers): If you use Homebrew, run:
    brew install openjdk@21 

    Follow any post-install instructions Homebrew prints — you may need to symlink the installation for system-wide access.

After installation, verify with java -version in Terminal.

One macOS-specific note: Apple Silicon (M1/M2/M3) Macs require ARM-compatible Java builds. Most modern distributions offer these directly, but always check the architecture label (ARM64 vs. x64) before downloading.

Installing Java on Linux 🐧

Linux gives you multiple paths depending on your distribution:

Using a package manager (easiest for most users):

DistributionCommand
Ubuntu / Debiansudo apt install default-jdk
Fedora / RHELsudo dnf install java-21-openjdk
Arch Linuxsudo pacman -S jdk-openjdk

These commands install OpenJDK from your distro's repositories. The version may lag slightly behind the latest release.

Manual installation: Download a tarball (.tar.gz) from adoptium.net or similar, extract it to a directory like /usr/local/java/, and update your PATH and JAVA_HOME manually in your shell profile (.bashrc, .zshrc, etc.).

SDKMAN (useful for managing multiple versions): If you work with multiple Java versions, SDKMAN lets you install and switch between them with simple commands:

sdk install java 21.0.3-tem sdk use java 21.0.3-tem 

Key Variables That Change the Right Approach

Not every installation path fits every situation. Several factors push people toward different decisions:

  • Purpose: Running a single app vs. doing active Java development leads to very different requirements (JRE vs. JDK, version constraints).
  • Version requirements: Some older applications are hard-coded to require Java 8 or Java 11. Installing only the latest version may cause compatibility issues if you need to support legacy software.
  • Operating system and architecture: ARM-based Macs and newer Linux environments require architecture-appropriate builds — a mismatch will either fail silently or throw errors at runtime.
  • Single version vs. multiple versions: Developers often need to run different projects on different Java versions simultaneously. Tools like SDKMAN, jenv, or IntelliJ IDEA's built-in JDK manager are designed for exactly this.
  • Corporate or managed environments: IT-managed machines may restrict what you can install or may have Java pre-configured in a non-standard path. Running java -version first is always worth doing before assuming nothing is installed.

After Installation: Common First-Time Issues

  • "java is not recognized" on Windows usually means PATH wasn't updated correctly.
  • Multiple Java versions conflicting is common if you've installed Java before without removing old versions.
  • macOS Gatekeeper warnings may appear on manually downloaded packages — right-click and choose "Open" to bypass for trusted downloads.

Whether you're installing for a single tool or setting up a full development environment, the version you choose, the distribution you pull from, and how your system manages environment variables all interact in ways that depend entirely on what you're trying to accomplish and what's already on your machine.