Permanently Set or Change $JAVA_HOME on Mac (macOS)

You make have noticed that if you use the export command JAVA_HOME = your/java/home/path on the console, it will only be active for the particular session. In order to permanently set $JAVA_HOME, you need to see it in the shell profile file, for Mac running on macOS it should be the .zshrc file,

Steps to Permanently Set $JAVA_HOME on Mac

  1. Open Terminal,
  2. Type: nano ~/.zshrc (or vi ~/.zshrc if you are a Vi guy!)
  3. Now add your JAVA_HOME=/your/java/jdk/home/path, somewhere in the file, if its empty add it at the start (then mostly you just created it :)) if it's not empty, it is good to add as the last line.
  4. Save the file (Control + X followed by Y, if using Nano Editor)
  5. Now just type zsh to refresh the shell or source ~/.zshrc to reflect the change permanently!

Permanently Set JAVA_HOME macOS

Have Questions? Post them here!
Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

πŸŽ‰ We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.