Install the Microsoft Build of OpenJDK

This article describes how to install the Microsoft Build of OpenJDK. To get the files mentioned in this article, see Download the Microsoft Build of OpenJDK.

ZIP and TAR.GZ packages

For Windows, Linux, and macOS, we produce ZIP (Windows) and TAR.GZ (Linux/macOS) packages. To install, extract one of these packages in a folder of your choice, then set the JAVA_HOME environment variable to that folder.

Alternately, you can use native installers for your OS of choice, as described in the next section.

Native installers

For Windows, we produce an MSI installer with a graphical interface. For macOS, we produce a PKG installer with similar features. These installers will automatically make the JDK tools available in your PATH.

For Linux, we produce DEB and RPM packages to be used with apt and rpm.

The following sections provide instructions for these installers.

Install on Windows

To install on any version of Windows, you can use the MSI packages or the ZIP package. If you're on Windows 10 or later, you can use the Windows Package Manager from your Windows Terminal.

Install via MSI

The MSI installer provides both a graphical and a console-only installation method. If you double-click on the MSI file, it will launch the tradition Windows application installer, where you can follow the instructions on the screen.

For widescale deployment, you can install the MSI on the command line using the following steps:

  1. Download the .msi file. For more information, see Download the Microsoft Build of OpenJDK.

  2. Choose the features you want to install from the following table:

    Feature Description
    FeatureMain Core installation (DEFAULT)
    FeatureEnvironment Update the PATH environment variable. (DEFAULT)
    FeatureJarFileRunWith Associate .jar files with Java applications. (DEFAULT)
    FeatureJavaHome Update the JAVA_HOME environment variable.
    FeatureOracleJavaSoft Updates registry keys HKLM\SOFTWARE\JavaSoft\.

    Note

    You can use FeatureOracleJavaSoft to prevent Oracle Java launching from PATH when Microsoft Build of OpenJDK is uninstalled. Reinstall Oracle Java if you need to restore the Oracle registry keys.

    You can use optional parameters that group some of the features together, as shown in the following example:

    Parameter Features
    INSTALLLEVEL=1 FeatureMain,FeatureEnvironment,FeatureJarFileRunWith
  3. Run the msiexec command command on the target workstation. Use the selected features, as shown in the following example.

    msiexec /i <package>.msi ADDLOCAL=FeatureMain,FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome INSTALLDIR="c:\Program Files\Microsoft\" /quiet
    

    Note

    You must use INSTALLDIR with FeatureMain.

    This example silently installs the Microsoft Build of OpenJDK, updates the PATH, associates .jar files with Java applications, and defines JAVA_HOME.

Install with the Windows Package Manager

To install with the Windows Package Manager, first install winget, and then open the Windows Terminal.

Next, use the following command to search for the Microsoft Build of OpenJDK packages:

winget search Microsoft.OpenJDK

You'll see output similar to the following:

Name                           Id                    Version
--------------------------------------------------------------
Microsoft Build of OpenJDK 17  Microsoft.OpenJDK.17  17.0.2.8.1

You can now install the package by referencing the Id shown above, using the following command:

winget install Microsoft.OpenJDK.17

This command produces an output similar to the following:

Found Microsoft Build of OpenJDK 17 [Microsoft.OpenJDK.17]
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licences to, third-party packages.
Downloading https://aka.ms/download-jdk/microsoft-jdk-17.0.2.8.1-windows-x64.msi
  ██████████████████████████████   160 MB /  160 MB
Successfully verified installer hash
Starting package install...
Successfully installed

Install on macOS

Packages for macOS are available through Homebrew or as standalone downloads in PKG or TAR.GZ formats.

To install the latest version with Homebrew:

brew install --cask microsoft-openjdk

This command produces a output similar to the following:

==> Downloading https://aka.ms/download-jdk/microsoft-jdk-17.0.2.8.1-macOS-x64.pkg
Already downloaded: /Users/foobar/Library/Caches/Homebrew/downloads/32c8e30d90fb2816bb4061265d7b3c6b1f953193feae7943d7dd7759e7ac15c6--microsoft-jdk-17.0.2.8.1-macOS-x64.pkg
==> Installing Cask microsoft-openjdk
==> Running installer for microsoft-openjdk; your password may be necessary.
Package installers may write to any location; options such as `--appdir` are ignored.
Password:
installer: Package name is Microsoft Build of OpenJDK
installer: Upgrading at base path /
installer: The upgrade was successful.
🍺  microsoft-openjdk was successfully installed!

Note

The package microsoft-openjdk points to the latest version of the Microsoft Build of OpenJDK.

To install other versions with Homebrew you need to tap the cask-versions repo first:

brew tap homebrew/cask-versions
brew install --cask microsoft-openjdk11

To install on macOS with the TAR.GZ package, just extract the file into a location. The JDK will be inside <location>/jdk-<version>/Contents/Home.

To install using the PKG installer, open the installer and follow the instructions. By default, the JDK will be installed at /Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home.

Uninstall on macOS

To uninstall the Microsoft Build of OpenJDK installed through Homebrew or PKG, use the following commands:

sudo rm -rf /Library/Java/JavaVirtualMachines/microsoft-17.jdk
sudo pkgutil --forget com.microsoft.17.jdk

To uninstall the package installed through the TAR.GZ package, simply delete the folder.

Install on Ubuntu

To install on Ubuntu 18.04 LTS and 20.04 LTS, open a terminal and run the following commands:

# Valid values are only '18.04' and '20.04'
# For other versions of Ubuntu, please use the tar.gz package
ubuntu_release=`lsb_release -rs`
wget https://packages.microsoft.com/config/ubuntu/${ubuntu_release}/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

After the repository is added, install the Microsoft Build of OpenJDK by running the following commands:

sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install msopenjdk-17

Note

You may have to update your default JDK selection, see here for details.

Install on Debian

Debian 9

To install on Debian 9, open a terminal and run the following commands:

wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/debian/9/prod.list -O /etc/apt/sources.list.d/microsoft-prod.list

After the repository is added, run the following commands:

sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install msopenjdk-17

Note

You may have to update your default JDK selection, see here for details.

Debian 10+

To install on Debian 10 and later, open a terminal and run the following commands:

sudo apt-get install wget lsb-release -y
wget https://packages.microsoft.com/config/debian/${lsb_release -rs}/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

After the repository is added, run the following commands:

sudo apt update
sudo apt install msopenjdk-17

Note

You may have to update your default JDK selection, see here for details.

Install on CentOS 7 (RPM)

To install on CentOS 7, open a terminal and run the following command:

sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm

After the repository is added, run the following command:

sudo yum install msopenjdk-17

Note

RPM packages for msopenjdk-17 may not update automatically to the latest minor version. Run yum install msopenjdk-17-17.0.2+8_LTS-1 to force update to latest release.

Change the default JDK on Linux

If you have several versions of OpenJDK installed on your system, use the following command to set the Microsoft Build of OpenJDK as the default:

For Debian/Ubuntu:

sudo update-java-alternatives --set msopenjdk-17-amd64

For CentOS, you can use the command alternative.

Provide feedback on the Microsoft Build of OpenJDK

Send us your comments, thoughts, and ideas to help us improve the Microsoft Build of OpenJDK. Visit our OpenJDK discussions page on GitHub to send us your feedback.

Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.