Quick way to set JAVA_HOME in mac
Okay — got new mac and playing around Java project. Now first thing is to set up my JAVA_HOME variable. Thought to write a post so that it’s helpful to others coming here. Read along.
Setting up the JAVA_HOME environment variable on a Mac is crucial for Java development. This guide will take you through the process step by step.

Step 1: Check Current JAVA_HOME Setting
Start by checking if JAVA_HOME is already set on your system.
Open the Terminal and type:
echo $JAVA_HOMEIf this returns a path, JAVA_HOME is already set. If not, proceed to the next step.
Step 2: Download and Install JDK
If JAVA_HOME is not set, you need to install the Java Development Kit (JDK).
- Visit JDK Archive.
- Download the
.tar.gzfile appropriate for your Mac. - Install the JDK by extracting the downloaded file.
Step 3: Set JAVA_HOME in Bash Profile
After installing JDK, you’ll need to set the JAVA_HOME variable.
- Open the Terminal.
- Type
nano ~/.bash_profileto open the Bash profile in a text editor. - Add the following line, replacing
/your/path/with the actual path to your JDK installation:
export JAVA_HOME=/your/path/jdk-21.0.1.jdk/Contents/Home4. Save the file and exit the editor.
Step 4: Update .zshrc File
If you’re using zsh instead of Bash:
- Create a
.zshrcfile by typingtouch ~/.zshrcin the Terminal. - Open it with
nano ~/.zshrc. - Add the following line:
source ~/.bash_profile4. Save and close the file.
Step 5: Verify the JAVA_HOME Setting
Open a new Terminal window and type:
echo $JAVA_HOMEThis should now print the path you set for JAVA_HOME. If it does, you've successfully set up JAVA_HOME on your Mac.
- Did this help? Be sure to clap and follow the writer
- Questions, feedback — drop a response below
- More POCs to come, subscribe to writer here
Have a great day!
