Skip to main content

Install Java JDK on Windows, macOS, and Linux

Every Java journey begins with a working JDK. The Java Development Kit provides the compiler (javac), runtime tools, and the JRE—everything you need to build and run Java applications. This guide walks you through installing a JDK on Windows, macOS, and Linux, configuring the essential environment variables, and verifying that your setup is correct.

Choose a current Long‑Term Support (LTS) release unless your project dictates otherwise. At the time of writing, JDK 21 and JDK 17 are the recommended LTS versions for production use. The steps below apply to any modern JDK distribution.

1. What You Need Before Installing​

  • Administrative access – required to install system‑wide packages or modify system paths on some operating systems.
  • Stable internet connection – to download the JDK distribution.
  • A terminal or command prompt – for running verification commands.
  • A decision on which Java version – prefer JDK 21 or 17 unless a specific project requires an older or newer version.

2. Choose a JDK Distribution​

We recommend using Eclipse Temurin (an OpenJDK distribution) as the default JDK for learning and development environments. If your project requirements, organizational policies, or commercial support needs require Oracle JDK, you may install Oracle JDK directly.

Several reliable distributions are available. The code you write and run is the same; the differences lie in licensing, update cadence, and platform support.

DistributionProviderLicenseNotes
Oracle JDKOracleOracle No‑Fee Terms (JDK 17+)Free for production; older versions may require a license.
Eclipse TemurinEclipse AdoptiumOpenJDK (GPL + Classpath)Community‑driven, widely adopted, TCK‑tested.
Amazon CorrettoAmazonGPL + ClasspathFree, long‑term support, AWS optimized.
Azul ZuluAzulGPL + ClasspathBroad platform support, commercial support available.
OpenJDK (upstream)OpenJDK communityGPL + ClasspathReference implementation, no commercial support.

Recommendation for most developers: Eclipse Temurin or Amazon Corretto. They are free, TCK‑tested, and receive regular security updates. For corporate environments, check your organization’s policies.

3. Install Java on Windows​

  1. Download the JDK
    Visit the Eclipse Temurin or your chosen distribution’s site, such as Oracle JDK. Select the .msi installer for Windows.

  2. Run the installer
    Launch the .msi file. Accept the license agreement. Keep the default installation directory (e.g., C:\Program Files\Eclipse Adoptium\jdk-21.0.4.7-hotspot\) or change it if needed.

  3. Set JAVA_HOME

    • Press Windows + Pause/Break → Advanced system settings → Environment Variables.
    • Under System variables, click New.
    • Variable name: JAVA_HOME
    • Variable value: the JDK installation path (e.g., C:\Program Files\Eclipse Adoptium\jdk-21.0.4.7-hotspot).
    • Click OK.
  4. Update PATH

    • In the same Environment Variables window, select the Path variable and click Edit.
    • Click New and add %JAVA_HOME%\bin.
    • Click OK to close all dialogs.
  5. Verify
    Open Command Prompt or PowerShell and run:

    java -version
    javac -version
    echo %JAVA_HOME%

    You should see version information for both java and javac, and JAVA_HOME should point to the JDK directory.

4. Install Java on macOS​

  1. Download the JDK
    Download the .pkg installer from your chosen distribution’s website (e.g., Eclipse Temurin for macOS).

  2. Install
    Double‑click the .pkg and follow the prompts. The JDK is typically installed in /Library/Java/JavaVirtualMachines/.

  3. Configure environment variables
    macOS uses zsh by default. Edit your shell profile:

    nano ~/.zshrc

    Add the following lines (adjust the version path if needed):

    export JAVA_HOME=$(/usr/libexec/java_home -v 21)
    export PATH=$JAVA_HOME/bin:$PATH

    If you use bash, edit ~/.bash_profile instead.

  4. Apply changes

    source ~/.zshrc
  5. Verify

    java -version
    javac -version
    echo $JAVA_HOME

    The output should show the installed JDK version.

    macOS note: The /usr/libexec/java_home utility helps manage multiple JDKs. You can list all installed versions with /usr/libexec/java_home -V.

5. Install Java on Linux​

The exact commands depend on your distribution and whether you prefer a package manager or a manual tarball.

Debian/Ubuntu (apt)

sudo apt update
sudo apt install temurin-21-jdk

If the Temurin repository is not configured, follow the Adoptium installation instructions to add it.

Fedora/RHEL/CentOS (dnf/yum)

# For Fedora
sudo dnf install temurin-21-jdk

# For older RHEL/CentOS
sudo yum install temurin-21-jdk

Arch Linux (pacman)

sudo pacman -S jdk-openjdk # or a specific version like jdk21-openjdk

Option B: Manual Tarball​

  1. Download the .tar.gz archive from your distribution’s site.

  2. Extract:

    tar -xzf jdk-21_linux-x64_bin.tar.gz
    sudo mv jdk-21.0.2 /usr/lib/jvm/
  3. Configure environment variables in ~/.bashrc or ~/.zshrc:

    export JAVA_HOME=/usr/lib/jvm/jdk-21.0.2
    export PATH=$JAVA_HOME/bin:$PATH
  4. Source the profile and verify.

Verification (all Linux methods)​

java -version
javac -version
echo $JAVA_HOME

If multiple JDKs are installed, use update-alternatives --config java (Debian/Ubuntu) or manually symlink the desired version.

6. Configure Environment Variables​

  • JAVA_HOME – points to the JDK installation root. Many tools (Maven, Gradle, IDE) rely on it to locate the JDK.
  • PATH – must include $JAVA_HOME/bin (or %JAVA_HOME%\bin on Windows) so that java, javac, and other binaries are accessible from any terminal.
  • Why it matters – without proper variables, build tools may fail, and the wrong Java version might be picked up. Consistent configuration prevents “works on my machine” issues.

7. Verify the Installation​

Beyond the basic version checks, ensure your environment is fully functional:

  1. Compile and run a test program
    Create HelloWorld.java:

    public class HelloWorld {
    public static void main(String[] args) {
    System.out.println("JavaDevPro is ready.");
    }
    }

    Compile and run:

    javac HelloWorld.java
    java HelloWorld

    You should see the printed message.

  2. Check for conflicting installations
    Run where java (Windows) or which java (macOS/Linux). The path should include the JDK you just installed.

  3. If the wrong version appears
    Reorder the PATH entries so the desired JDK’s bin directory appears first. On Linux/macOS, you can also use sudo update-alternatives or sdkman to manage multiple JDKs.

8. Common Installation Problems​

SymptomProbable CauseSolution
java command not foundPATH does not include JDK bin.Add %JAVA_HOME%\bin (Windows) or $JAVA_HOME/bin (macOS/Linux) to your PATH.
javac not found, but java worksJRE installed instead of JDK.Install a full JDK, not just a JRE.
JAVA_HOME not setVariable not created or not exported.Create the variable and restart the terminal or source your shell profile.
Wrong version appearsAnother Java is higher in PATH.Reorder PATH or use absolute paths.
Permission denied (Linux/macOS)Installation directory not writable.Use sudo or install to a user‑writable location.
Installer fails on WindowsLack of admin privileges.Right‑click the installer and select “Run as administrator”.
Multiple JDK installations conflictSeveral JDKs on PATH or JAVA_HOME mismatch.Uninstall unwanted versions, use a version manager (sdkman), or set JAVA_HOME explicitly.

9. Quick Reference Table​

PlatformMain StepsVerification Commands
WindowsDownload .msi, install, set JAVA_HOME, add bin to PATHjava -version, javac -version, echo %JAVA_HOME%
macOSDownload .pkg, install, update ~/.zshrc, source itjava -version, javac -version, echo $JAVA_HOME
LinuxUse package manager or tarball, set environment variablesjava -version, javac -version, echo $JAVA_HOME

Your Java environment is ready. Now you can:

With the JDK installed, you have taken the first concrete step toward professional Java engineering. Keep this guide handy whenever you set up a new machine or onboard a colleague.