Java Development Setup Guide for macOS (Intel-Based)
This guide provides a comprehensive walkthrough to install and configure the Java development environment on Intel-based macOS systems.
[!NOTE] If you are using a modern Mac with Apple Silicon (M1/M2/M3 chips), please refer to the optimized Apple Silicon Java Setup Guide for native ARM64 setup instructions.
Installation Checklist
- Install Homebrew Package Manager
- Download and Install Java JDK (LTS 17 or 21)
- Set
JAVA_HOMEin Zsh configuration (.zshrc) - Verify JDK Installation via Terminal
- Install IDE (IntelliJ IDEA / VS Code)
- Install Git Version Control
- Write, compile, and run your first Java test program
Step 1: Install Homebrew (Recommended)
Homebrew is the standard package manager for macOS, making it simple to install and update software.
- Open your Terminal (found in
/Applications/Utilities/or via Spotlight). - Run the following installation command:
- Once installed, verify that Homebrew is working:
Step 2: Install Java JDK
Option A: Installing via Homebrew (Recommended)
This installs the latest open-source JDK distribution and links it directly to macOS System frameworks.
After installation finishes, create a symbolic link so the macOS system Java wrapper can discover it:
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Option B: Manual Installation (Alternate)
- Go to Adoptium's official website: Adoptium Temurin Releases.
- Choose macOS as the operating system and x64 (Intel) as the architecture.
- Download the
.dmginstaller. - Open the
.dmgpackage and double-click the installer icon to run the wizard.
Step 3: Configure Environment Variables
Modern macOS uses zsh as the default shell. You need to configure it to automatically export the JAVA_HOME path.
-
Open your shell profile configuration:
-
Add the following lines to configure dynamic version lookup and update the path search priorities:
-
Save and close the file (
Ctrl + O, thenEnter, thenCtrl + Xto exit nano). - Apply changes immediately to the current terminal window:
Step 4: Verify the Installation
Execute the following commands to confirm that Java compiles and runs successfully:
Expected Output:
openjdk version "21.0.1" 2023-10-17 LTS
OpenJDK Runtime Environment Temurin-21.0.1+12 (build 21.0.1+12-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.1+12 (build 21.0.1+12-LTS, mixed mode, sharing)
javac 21.0.1
Step 5: Install Recommended IDEs and Tools
Install one of the primary code editors below:
- IntelliJ IDEA (Recommended): Industry-standard Java IDE.
- Download IntelliJ IDEA for macOS (Choose Intel macOS version).
- VS Code: Lightweight and modular.
- Download VS Code for macOS (Choose Intel chip version).
Step 6: Install Git Version Control
- Install Git directly using Homebrew:
- Verify the command line version:
Step 7: Write, Compile, and Run Your First Program
Let's test the command line compiler interface:
-
Create a file named
HelloWorld.javain any workspace directory: -
Open Terminal, navigate to the folder where you created the file, and run:
Output:
Common Issues and Troubleshooting
[!WARNING]
Permission Denied during symlinking
- Cause: The symlink command requires root privileges.
- Fix: Ensure you prefix the command with
sudo(sudo ln -sfn ...). Enter your Mac administrator login password when prompted.[!IMPORTANT]
Terminal changes not loading
- Cause: You added variables to
~/.zshrcbut did not refresh or restart the active terminal session.- Fix: Run
source ~/.zshrcin your active tab or close and reopen Terminal.
Back to Module Home: 01_SETUP README