Last Updated:

Microsoft OpenJDK 21 Download: A Comprehensive Guide

Java remains one of the most widely used programming languages, powering enterprise applications, mobile apps, and cloud services. With the release of Java 21 (an LTS, Long-Term Support, version), developers and organizations have access to new features like virtual threads, record patterns, and sequenced collections. Microsoft, a key contributor to the OpenJDK project, offers its own distribution of OpenJDK—Microsoft Build of OpenJDK—optimized for enterprise use cases, with long-term support and security updates.

This blog provides a detailed, step-by-step guide to downloading and installing Microsoft OpenJDK 21 across Windows, macOS, and Linux. We’ll cover manual downloads, package managers, verification steps, best practices, and example usage to ensure a smooth setup.

Table of Contents#

  1. What is Microsoft OpenJDK 21?
  2. Prerequisites
  3. Downloading Microsoft OpenJDK 21
  4. Verifying the Download
  5. Installing Microsoft OpenJDK 21
  6. Verifying the Installation
  7. Best Practices
  8. Example Usage
  9. Troubleshooting Common Issues
  10. Conclusion
  11. References

What is Microsoft OpenJDK 21?#

Overview#

Microsoft Build of OpenJDK is a free, open-source distribution of the Java Development Kit (JDK) based on the OpenJDK project. It is optimized for production use, with enterprise-grade support, security updates, and compatibility with Java SE standards. Microsoft OpenJDK 21 is the LTS release corresponding to Java 21, supported until at least October 2031 (per Microsoft’s support policy).

Key Features of Java 21#

Java 21 introduces several groundbreaking features, including:

  • Virtual Threads: Lightweight threads that reduce overhead for high-throughput applications.
  • Record Patterns: Enhance pattern matching for records to simplify data processing.
  • Sequenced Collections: New interfaces (SequencedCollection, SequencedMap) for ordered collections.
  • String Templates (Preview): Simplify string interpolation with embedded expressions.
  • Unnamed Classes and Instance Main Methods (Preview): Reduce boilerplate for simple programs.

Why Choose Microsoft OpenJDK?#

  • Enterprise Support: Backed by Microsoft’s support team, with security updates and bug fixes.
  • Optimized for Cloud: Tuned for Azure and cloud environments, with containerization support.
  • Cross-Platform: Available for Windows, macOS, and Linux (x64, ARM64).
  • Compliance: Adheres to Java SE standards, ensuring compatibility with existing Java applications.
  • Free: No licensing fees—ideal for both development and production.

Prerequisites#

Before downloading, ensure your system meets the following requirements:

  • Operating System: Windows 10/11, macOS 11+ (Big Sur or later), or a Linux distribution (e.g., Ubuntu 20.04+, RHEL 8+).
  • Architecture: x64 or ARM64 (check your system’s CPU architecture).
  • Disk Space: At least 200 MB free for the JDK installation.

Downloading Microsoft OpenJDK 21#

Microsoft provides multiple ways to download OpenJDK 21: manual downloads from the official site, package managers, or cross-platform tools like SDKMAN!. Below are OS-specific guides.

Windows#

1. Manual Download#

  1. Visit the Microsoft OpenJDK Download Page.
  2. Under "Microsoft Build of OpenJDK 21", select your architecture (x64 or ARM64).
  3. Download the .zip file (e.g., openjdk-21.0.1_windows-x64_bin.zip).

2. Package Managers#

For automated installations, use Chocolatey or Winget:

Chocolatey:

# Install Chocolatey (if not already installed)
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
 
# Install Microsoft OpenJDK 21
choco install microsoft-openjdk21 -y

Winget (Windows Package Manager):

# Install Microsoft OpenJDK 21 via Winget
winget install Microsoft.OpenJDK.21

macOS#

1. Manual Download#

  1. Visit the Microsoft OpenJDK Download Page.
  2. Under "Microsoft Build of OpenJDK 21", select macOS and your architecture (x64 or ARM64).
  3. Download the .tar.gz file (e.g., openjdk-21.0.1_macos-x64_bin.tar.gz).

2. Homebrew#

Homebrew is the most popular package manager for macOS:

# Update Homebrew
brew update
 
# Install Microsoft OpenJDK 21
brew install --cask microsoft-openjdk@21

Linux#

1. Debian/Ubuntu (APT)#

  1. Import Microsoft’s GPG key:

    curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
    sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
  2. Add the Microsoft OpenJDK repository:

    sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/microsoft.list'
  3. Install OpenJDK 21:

    sudo apt update
    sudo apt install microsoft-openjdk-21

2. RHEL/CentOS (YUM/DNF)#

  1. Add the Microsoft repository:

    sudo rpm -Uvh https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm
  2. Install OpenJDK 21:

    sudo dnf install microsoft-openjdk-21  # For RHEL 8+/CentOS 8+
    # OR
    sudo yum install microsoft-openjdk-21  # For older RHEL/CentOS

3. SDKMAN! (Cross-Platform)#

SDKMAN! is a popular tool for managing multiple Java versions. It works on Linux, macOS, and WSL:

# Install SDKMAN! (if not already installed)
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
 
# List available Java versions (filter for Microsoft)
sdk list java | grep -i microsoft
 
# Install Microsoft OpenJDK 21 (use the identifier from the list, e.g., 21.0.1-ms)
sdk install java 21.0.1-ms

Verifying the Download#

To ensure the downloaded file is not corrupted or tampered with, verify its SHA256 checksum against Microsoft’s official checksum.

Steps:#

  1. On the Microsoft OpenJDK Download Page, find the "Checksum" link next to your download (e.g., openjdk-21.0.1_windows-x64_bin.zip.sha256).
  2. Download the checksum file.
  3. Verify the hash using a tool like sha256sum (Linux/macOS) or CertUtil (Windows).

Example (Linux/macOS):

sha256sum openjdk-21.0.1_linux-x64_bin.tar.gz
# Compare output with the checksum in the .sha256 file

Example (Windows):

CertUtil -hashfile openjdk-21.0.1_windows-x64_bin.zip SHA256
# Compare output with the checksum in the .sha256 file

If the hashes match, the download is valid.

Installing Microsoft OpenJDK 21#

Windows#

  1. Extract the downloaded .zip file to a directory (e.g., C:\Program Files\Microsoft\jdk-21.0.1).
  2. Add the bin directory to your system PATH:
    • Open System PropertiesAdvancedEnvironment Variables.
    • Under "System Variables", select PathEditNew.
    • Add C:\Program Files\Microsoft\jdk-21.0.1\bin (adjust path as needed).

macOS#

  1. Extract the .tar.gz file:
    tar -xzf openjdk-21.0.1_macos-x64_bin.tar.gz
  2. Move the extracted folder to /Library/Java/JavaVirtualMachines/ (recommended):
    sudo mv jdk-21.0.1.jdk /Library/Java/JavaVirtualMachines/

Linux#

If using APT/YUM, the JDK is installed to /usr/lib/jvm/microsoft-openjdk-21-amd64/ (x64) or similar. No manual extraction is needed.

Verifying the Installation#

Checking Java Version#

Open a terminal/command prompt and run:

java -version

You should see output like:

openjdk version "21.0.1" 2023-10-17
OpenJDK Runtime Environment Microsoft-8035023 (build 21.0.1+12-LTS)
OpenJDK 64-Bit Server VM Microsoft-8035023 (build 21.0.1+12-LTS, mixed mode, sharing)

To verify the compiler:

javac -version

Output:

javac 21.0.1

Setting JAVA_HOME#

Many tools (e.g., IDEs, build systems) require the JAVA_HOME environment variable.

Windows:#

  1. Open Environment Variables.
  2. Under "System Variables", click New.
  3. Set Variable name to JAVA_HOME and Variable value to the JDK installation path (e.g., C:\Program Files\Microsoft\jdk-21.0.1).

macOS/Linux:#

Add to ~/.bashrc, ~/.zshrc, or ~/.profile:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-21.0.1.jdk/Contents/Home  # macOS
# OR
export JAVA_HOME=/usr/lib/jvm/microsoft-openjdk-21-amd64  # Linux

Apply changes:

source ~/.bashrc  # or ~/.zshrc

Best Practices#

  1. Use Version Managers: Tools like SDKMAN! or jEnv help manage multiple Java versions, avoiding conflicts.
  2. Keep JDK Updated: Microsoft releases security patches for OpenJDK 21. Use apt update, brew upgrade, or SDKMAN! to stay current.
  3. Download from Official Sources: Only use the Microsoft OpenJDK page to avoid malware.
  4. Avoid System-Wide Installs (Development): For development, use user-specific installs (e.g., SDKMAN!) instead of system directories.
  5. Set JAVA_HOME: Always configure JAVA_HOME to ensure tools use the correct JDK.

Example Usage#

Hello World Program#

Create a simple Java class to test the installation:

// HelloWorld.java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, Microsoft OpenJDK 21!");
    }
}

Compile and run:

javac HelloWorld.java
java HelloWorld
# Output: Hello, Microsoft OpenJDK 21!

Java 21 Feature: Virtual Threads#

Java 21’s virtual threads enable high-throughput concurrency with minimal overhead. Example:

// VirtualThreadsExample.java
public class VirtualThreadsExample {
    public static void main(String[] args) throws InterruptedException {
        int numberOfThreads = 10_000;
        var executor = java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor();
        
        for (int i = 0; i < numberOfThreads; i++) {
            int taskId = i;
            executor.submit(() -> {
                System.out.println("Task " + taskId + " running on virtual thread: " + Thread.currentThread());
                return null;
            });
        }
        
        executor.close();
        System.out.println("All tasks completed.");
    }
}

Compile and run:

javac VirtualThreadsExample.java
java VirtualThreadsExample

This creates 10,000 virtual threads—something impractical with traditional OS threads—demonstrating Java 21’s scalability.

Troubleshooting Common Issues#

"java: command not found"#

  • Cause: JDK bin directory not in PATH.
  • Fix: Verify PATH includes the JDK bin folder (e.g., C:\Program Files\Microsoft\jdk-21.0.1\bin on Windows).

Multiple JDK Versions#

  • Issue: The system uses an older JDK version.
  • Fix: Use sdk use java 21.0.1-ms (SDKMAN!) or update PATH/JAVA_HOME to point to Microsoft OpenJDK 21.

JAVA_HOME Misconfiguration#

  • Symptom: Tools like Maven/Gradle fail to find the JDK.
  • Fix: Ensure JAVA_HOME points to the root of the JDK directory (not bin).

Conclusion#

Microsoft OpenJDK 21 is a robust, enterprise-grade JDK distribution that brings Java 21’s powerful features to developers and organizations. By following this guide, you can easily download, install, and verify OpenJDK 21 on Windows, macOS, or Linux. Adopting best practices like version management and security updates will ensure a stable and secure Java environment.

Whether you’re building cloud-native apps, microservices, or desktop applications, Microsoft OpenJDK 21 provides the performance and reliability needed for production workloads.

References#