How to Install OpenJDK on Windows, macOS & Linux (Step-by-Step)

how-to-install-openjdk-on-windows-macos-linux

OpenJDK is one of coexisting branch offered by Java Development Kit (JDK) as open-source utility used for building and running Java applications. It is a simple and easy method to run Java-based content while working under GPL-2.0 license, and includes a Java Machine, the Java Class Library, and a Java-bytecode compiler. In this guide, we will discuss step-by-step installation for different operating systems including macOS, Windows, and Linux to enable your device to run Java-based programs.

How to Install OpenJDK on macOS, Windows, Linux

Here we will discuss installation process of OpenJDK on different operating systems;

1 Install OpenJDK on macOS

You can use two methods to install OpenJDK on macOS. Here we will discuss both for your ease to select any one.

Manual Installation

1. Unlock your macOS, navigate to official website of OpenJDK, select your required version, and press Download button to download it.

2. The downloaded file will be saved to ‘Download’ folder by default.

3. Locate the downloaded file, extract .tar.gz file after double-clicking it.

instal-openjdk-macos,windows,linux-1.1

4. Enter following command to Terminal to move the extracted folder to /Library/Java/JavaVirtualMachines/

        Sudo my jdk-21.jdk /Library/Java/JavaVirtualMachines/

5. Check the Java version to verify the installation;

                java  -version
instal-openjdk-macos,windows,linux-1.6

6. Set the JAVA—HOME Environment Variable

7. Launch your shell configuration file; enter the command

     Nano ~/ .zshrc

8. Next, enter the following string

Export  JAVA—HOME=”/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home”
instal-openjdk-macos,windows,linux-1.15

9. Save the file to your required location, and close it.

instal-openjdk-macos,windows,linux-1.9

10. Reluanch the configuration

         Source ~/.zshrc

11. Verify the JAVA HOME variable:

Use Homebrew

If you can’t capable of installing OpenJDK manually, you need to move Homebrew, and try to install it. Here is how it works;

Step 1: Check if Java is installed

1. It is necessary that Java is installed on your macOS. For the purpose, press Command + Space, type Terminal, and press Enter key to open Terminal.

2. Insert following command;

    Java  -version

3. Here, you will see the Java version if it is installed on your macOS, otherwise, you will receive a notification “Java isn’t installed”.

Step 2: Install Homebrew

1. Homebrew is a package manager to enable your macOS to install different software such as OpenJDK.

2. Enter the following command to start installation of Homebrew;

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

3. Complete installation process while following the on-screen instructions.

Step 3: Install OpenJDK

1. Now, your macOS is ready to install the latest version of OpenJDK. You need to open Terminal, and run the following command;

      brew  install  openjdk
instal-openjdk-macos,windows,linux-1.16

2. The latest version of OpenJDK will be installed on your macOS by Homebrew.

Step 4: Installation Verification

1. Check version to confirm the installation of OpenJDK. Enter the command

       java  -version

2. Following output will show the installed version of OpenJDK;

openjdk version "21.0.1" 2025-01-01
OpenJDK Runtime Environment (build 21.0.1+12)
OpenJDK 64-Bit Server VM (build 21.0.1+12, mixed mode)

2 Install OpenJDK on Windows

Here is how it works;

Step 1: Download JDK

1. Open your computer, use your browser, and navigate to official website of OpenJDK to download it

2. JDK 21 > Windows > Download “x64 Installer” (“jdk-21_windows-x64_bin.exe”)

instal-openjdk-macos,windows,linux-1.1.1

Step 2: Install JDK

1. The downloaded .exe file will be saved by default, simply move to ‘Download’ folder, extract .exe file, and double-click to run the installer. It will install in directory by default

   “C:\Program Files\Java\jdk-21”.

2. Open File Explorer, and go to “C:\Program  Files\Java” to check the directories to locate JDK Installed Directory jdk-21.

3. Refer the JDK Installed Directory as %JAVA_HOME%

Step 3: The Installation Verification

1. Run Command Prompt by launching the “cmd” command.

2. Check is JDK’s “bin” is listed in PATH, enter the following string

PATH=c:\Program Files\Java\jdk-{xx.y.z}\bin;other enteries

3. Execute the following command to ensure the installation of JDK/JRE;

// Display the JDK  Version

javac  -version
instal-openjdk-macos,windows,linux-1.8

java   21.0.1

// Display the JRE Version

java  -version

java version  “21.0.1” 2023-10-17 LTS

Java ™  SE  Runtime  Environment  (build 21.0.1+12-LTS-29)

Java HotSpot (TM) 64-Bit Server VM  (build 21.0.1.12-LTS-29, mixed mode, sharing

Step 4: Run a Java Program

1. After completing installation and configuration process, you need to run a Java program, follow the given steps

2. Use your text editor to create new file i.e. HelloWorld.java

3. Insert given code in the file

Public class HellowWorld  {

instal-openjdk-macos,windows,linux-1.12

  

Public static void main (String []  args)  {

        System.out.printIn (“Hello, world!” )

   }

}

3. Save your file in C:\JavaProjects folder

4. Run cd command to launch Command Prompt, and go to the folder

  cd C:\JavaProjects
instal-openjdk-macos,windows,linux-1.13

5. Use following command to compile the program

     java  HelloWorld. Java

6. You will see “Hello, World!” in the command prompt.

instal-openjdk-macos,windows,linux-1.7

3 Install OpenJDK on Linux

To install OpenJDK on Linux, it is necessary to have administrative privileges on the Linux system. Moreover, you have some understanding for JDK and command-line interface

Let’s start the installation process;

1. Launch your Teminal, and execute the following command to update the package index;

       sudo  apt  update
instal-openjdk-macos,windows,linux-1.5

2. Insert the following command to install the OpenJDK

     sudo apt install -y java-1.8.0-amazon-corretto-devel

3. You can change the version by replacing 1.8.0 version into your desired version.

instal-openjdk-macos,windows,linux-1.14

Verify the Installation

Launch terminal, and enter the following command to verify the correct installation of OpenJDK

       java –version

The installed Java version will show in terminal, and you are allowed to develop and run Java applications.

Conclude

OpenJDK is the best solution to build and run Java-based program on different devices. You can install it easily using different methods. It is available for Windows, macOS, and Linux operating systems. You need only to follow the aforementioned instructions for any of specific operating system, and install it easily.


Wamiq Rafique


×

Get More Updates

📲 Join our WhatsApp Channel

🐦 Follow us on Twitter