Quantcast
Channel: Baeldung
Viewing all articles
Browse latest Browse all 4535

Install OpenJDK on Windows

$
0
0

1. Overview

Java plays a pivotal role in modern software development, empowering many applications and systems. To harness the power of Java on our machine, we need to install the Java Development Kit (JDK). While Oracle JDK is a popular choice, OpenJDK offers an open-source alternative with similar functionality.

In this article, we’ll explore various approaches to installing OpenJDK on a Windows environment, catering to different preferences and requirements.

2. Manual Installation

This method involves downloading the OpenJDK distribution directly from the official website or trusted repositories such as AdoptOpenJDK.

Once downloaded, extract the archive’s contents to a preferred location on our machine. It’s essential to configure environment variables such as PATH and JAVA_HOME to point to the directory where OpenJDK is installed. Let’s proceed by accessing the control panel and navigating to System settings:

System Settings

Selecting the Advanced system settings will prompt a dialog box to appear:

Advanced Settings

Let’s see the system and user variables now by clicking on Environment Variables. Here, we’ll modify the PATH variable and include the JAVA_HOME variable. The JAVA_HOME variable should indicate the installation directory of OpenJDK, while the PATH variable should direct to the bin directory of the JDK.

JAVA_HOME

In our case, JAVA_HOME will be C:\Program Files\Java\jdk-21.0.2 and PATH will be C:\Program Files\Java\jdk-21.0.2\bin

Finally, we can confirm the installation’s success by running the following command in the command prompt:

> java -version

After running the command above, a similar output will be displayed in the command prompt:Version

3. Chocolatey Package Manager

Chocolatey is a popular package manager for Windows that simplifies the installation and management of software packages. It provides a command-line interface (CLI) that allows users to search for, install, and uninstall software packages with ease, similar to package managers like apt on Ubuntu or Homebrew on macOS.

We need to first install Chocolatey on our machine before proceeding. Let’s open an elevated command and run the following command:

> 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'))

Once Chocolatey is installed, we can move forward with installing OpenJDK using it. Running the below command will install Java:

> choco install openjdk

4. Scoop Package Manager

Similar to Chocolatey, Scoop is another package manager designed specifically for Windows. Scoop is geared towards individual users rather than system-wide installations. It installs packages in the user’s home directory, which doesn’t require administrative privileges.

To get started with Scoop, we must first install it:

> <span class="token">Set-ExecutionPolicy</span> <span class="token">-</span>ExecutionPolicy RemoteSigned <span class="token">-</span>Scope CurrentUser
> <span class="token">Invoke-RestMethod</span> <span class="token">-</span>Uri https:<span class="token">/</span><span class="token">/</span>get<span class="token">.</span>scoop<span class="token">.</span>sh <span class="token">|</span> <span class="token">Invoke-Expression</span>

Now, to install OpenJDK using Scoop, we need to open PowerShell as an administrator and execute the following commands:

> scoop bucket add java
> scoop install openjdk

5. Using Third-Party Installers

Some third-party tools and utilities offer simplified installation procedures for OpenJDK on Windows. For instance, tools like SDKMAN! and WinGet provide an easy-to-use interface for managing software installations, including OpenJDK.

We can explore these options if we prefer a more streamlined installation process with additional features and customization options.

6. Conclusion

In this article, we explored different ways to install OpenJDK on our Windows machine. We can either opt for manual installation, package managers like Chocolatey or Scoop, or third-party installers, each method offers its advantages in simplicity, customization, and automation.

We can choose the approach that best fits our preferences and workflow.

       

Viewing all articles
Browse latest Browse all 4535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>