Overview

This article explains how to properly set up Java Development Kit (JDK) 17 on macOS systems, ensuring that the correct paths are configured in your shell environment. OpenJDK17 is preinstalled on Managed Server Plans. 


Environment

  • Operating Systems: macOS (Intel and Apple Silicon)

  • Shell Environments: Bash, Zsh

  • Software: OpenJDK 17 (installed via Homebrew)


Configuration Steps

For Apple Silicon Macs (M series)

If using Bash:

echo 'export JAVA_HOME="/opt/homebrew/opt/openjdk@17"' >> ~/.bash_profile
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

If using Zsh (default shell on newer macOS):

echo 'export JAVA_HOME="/opt/homebrew/opt/openjdk@17"' >> ~/.zshrc
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc


For Intel-based Macs

If using Bash:

echo 'export JAVA_HOME="/usr/local/opt/openjdk@17"' >> ~/.bash_profile
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

If using Zsh (default shell on newer macOS):

echo 'export JAVA_HOME="/usr/local/opt/openjdk@17"' >> ~/.zshrc
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc


Verification

  • To verify that Java 17 is correctly configured, run:
  • java --version
  • You should see output indicating OpenJDK 17.x is in use.


Troubleshooting

  • If another Java version is still being used, check:
    • The order of paths in your $PATH variable
    • Any JAVA_HOME environment variables that might be overriding your configuration


Additional Notes

  • This configuration adds the OpenJDK 17 binaries to the beginning of your PATH, making them the first choice when executing Java commands

  • The paths are determined by Homebrew's installation locations, which differ between Apple Silicon and Intel processors

  • Remember to source your profile file or restart your terminal after making changes



Interested in MacinCloud Managed Servers?

Visit the Managed Server Plan page to obtain a Managed server.


Do you require full root/admin privileges on a MacinCloud Server?

Find out more about MacinCloud Dedicated Server Plans
.