Java Development Setup Guide for Apple Silicon (M1/M2/M3)
This guide provides a comprehensive walkthrough to configure a native ARM64 Java development environment optimized for Apple Silicon (M1/M2/M3) Macs.
Installation Checklist
- Install Homebrew Package Manager
- Add Homebrew to your shell environment paths
- Install native ARM64 Java JDK (LTS 17 or 21)
- Set
JAVA_HOMEenvironment variable - Verify JDK installation via Terminal
- Install native ARM64 IDE (IntelliJ IDEA / VS Code)
- Install Git Version Control
- Write, compile, and run your first Java test program
Step 1: Install Homebrew
Homebrew installs binary packages natively in /opt/homebrew on Apple Silicon Macs.
- Open your Terminal.
- Run the Homebrew installation script:
- CRITICAL STEP: Add Homebrew to your Zprofile so that the shell can find the
brewcommand natively. Run the following commands in your Terminal:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
- Verify Homebrew is working:
Step 2: Install Native ARM64 Java JDK
Avoid running Intel-compiled JDK versions through Rosetta translation, as they consume more power and run slower.
Option A: Install via Homebrew (Recommended)
Install the default open-source JDK distribution:
Link the JDK to macOS system libraries so system frameworks can discover it:
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Option B: Azul Zulu JDK (Excellent for ARM64 Performance)
Azul Systems provides high-performance, native ARM64 JDK builds for Apple Silicon:
Step 3: Configure Environment Variables
-
Open your Zsh profile configuration:
-
Add these lines to resolve the path of the active JDK dynamically:
-
Save and close nano (
Ctrl + O, thenEnter, thenCtrl + X). - Reload the configurations in your current shell session:
Step 4: Verify the Installation
Confirm that Java runs natively on Apple Silicon:
Expected Output:
Ensure that aarch64 or 64-Bit indicates a native ARM compiler.
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)
Step 5: Install Native ARM64 IDEs
Make sure you download the Apple Silicon builds of your favorite editors:
- IntelliJ IDEA (Recommended): Download the macOS version. Click the dropdown and select the Apple Silicon option.
- Download IntelliJ IDEA
- VS Code: Download and run the native Apple Silicon zip/installer.
- Download VS Code
Step 6: Install Git Version Control
- Install native Git:
- Verify the command line version:
Step 7: Write, Compile, and Run Your First Program
Let's test compilation and execution:
-
Create a file named
HelloWorld.javain a local folder: -
Open Terminal, change directory (
cd) to the folder containing the file, and run:
Output:
Important Notes for Apple Silicon
[!TIP] * Check Architecture: If you want to check whether your Java processes are running natively or through Rosetta translation, run
ps aux | grep javawhile a program is running, or open Activity Monitor, find thejavaprocess, and check the type column (should say Apple and not Intel). * Homebrew Paths: Remember that Homebrew installs packages in/opt/homebrewfor Apple Silicon instead of/usr/localwhich is used for Intel Macs. Keep this in mind when referencing libraries.
Common Issues and Troubleshooting
[!WARNING]
zsh: command not found: brew
- Cause: You installed Homebrew but forgot to configure shell environment variables to add the
/opt/homebrew/binpath.- Fix: Rerun Step 1, part 3:
Back to Module Home: 01_SETUP README