![]() |
VOOZH | about |
Java is a popular programming language used to build web, mobile, and desktop applications. To create and run Java programs, you need the Java Development Kit (JDK). OpenJDK is the free and open-source version of the JDK, widely used by developers on macOS and other systems.
You can install OpenJDK on macOS in two simple ways:
Homebrew is a package manager for macOS that makes software installation simple and quick.
Step 1: Check If Java Is Already Installed
Command + Space, type Terminal, and hit Enter).java -version
Step 2: Install Homebrew (If Not Installed)
brew --version
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 3: Install OpenJDK
brew install openjdk
Step 4: Verify the Installation
java -version
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)
Step 5: Set JAVA_HOME (Optional)
JAVA_HOME environment variable to be set. Here’s how you can set it:
nano ~/.zshrc
export JAVA_HOME="$(brew --prefix openjdk)/libexec/openjdk.jdk/Contents/Home"
Ctrl + O, then Enter, and Ctrl + X to exit).
source ~/.zshrc
JAVA_HOME variable:
echo $JAVA_HOME
If you prefer not to use Homebrew, you can manually download and install OpenJDK from the official website:
Step 1: Download OpenJDK
.tar.gz file for your desired version.Step 2: Extract the File
Step 3: Move the Folder
sudo mv jdk-21.jdk /Library/Java/JavaVirtualMachines/
Replace jdk-21.jdk with your actual folder name if different.
Step 4: Verify Installation
java -version
Step 5: Set JAVA_HOME
nano ~/.zshrc
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home"
source ~/.zshrc
echo $JAVA_HOME