Skip to content

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_HOME in 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

Homebrew is the standard package manager for macOS, making it simple to install and update software.

  1. Open your Terminal (found in /Applications/Utilities/ or via Spotlight).
  2. Run the following installation command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Once installed, verify that Homebrew is working:
brew -v

Step 2: Install Java JDK

This installs the latest open-source JDK distribution and links it directly to macOS System frameworks.

brew install openjdk

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)

  1. Go to Adoptium's official website: Adoptium Temurin Releases.
  2. Choose macOS as the operating system and x64 (Intel) as the architecture.
  3. Download the .dmg installer.
  4. Open the .dmg package 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.

  1. Open your shell profile configuration:

    nano ~/.zshrc
    

  2. Add the following lines to configure dynamic version lookup and update the path search priorities:

    export JAVA_HOME=$(/usr/libexec/java_home)
    export PATH=$JAVA_HOME/bin:$PATH
    

  3. Save and close the file (Ctrl + O, then Enter, then Ctrl + X to exit nano).

  4. Apply changes immediately to the current terminal window:
    source ~/.zshrc
    

Step 4: Verify the Installation

Execute the following commands to confirm that Java compiles and runs successfully:

java -version
javac -version

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

Install one of the primary code editors below:


Step 6: Install Git Version Control

  1. Install Git directly using Homebrew:
    brew install git
    
  2. Verify the command line version:
    git --version
    

Step 7: Write, Compile, and Run Your First Program

Let's test the command line compiler interface:

  1. Create a file named HelloWorld.java in any workspace directory:

    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello, macOS Java!");
        }
    }
    

  2. Open Terminal, navigate to the folder where you created the file, and run:

    javac HelloWorld.java
    java HelloWorld
    

Output:

Hello, macOS Java!

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 ~/.zshrc but did not refresh or restart the active terminal session.
  • Fix: Run source ~/.zshrc in your active tab or close and reopen Terminal.

Back to Module Home: 01_SETUP README