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;
1Install 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.
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
6. Set the JAVA—HOME Environment Variable
7. Launch your shell configuration file; enter the command
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
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)
2Install 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”)
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
3. Execute the following command to ensure the installation of JDK/JRE;
// Display the JDK Version
javac -version
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 {
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
5. Use following command to compile the program
java HelloWorld. Java
6. You will see “Hello, World!” in the command prompt.
3Install 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
2. Insert the following command to install the OpenJDK
3. You can change the version by replacing 1.8.0 version into your desired version.
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.