Setup JAVA_HOME on Apple Mac

Download the latest java from Oracle https://www.oracle.com/java/technologies/downloads/#jdk19-mac

Go to Oracle Java Download and follow the installer next steps and complete the installation (Arm 64 RPM Package for Mac Apple chip and X64 RPM Package for intel chip )
  1. Open terminal and check the java version
java --version
java 19 2022-09-20
Java(TM) SE Runtime Environment (build 19+36-2238)
Java HotSpot(TM) 64-Bit Server VM (build 19+36-2238, mixed mode, sharing)

2. Check if JAVA_HOME is set echo $JAVA_HOME

3. If it returned empty then on the home / check for the file ~/.zshenv by hitting ls -al

4. If the file already exist open it if not found create using touch ~/.zshenv

5. Open the file using open ~/.zshenv

6. on the terminal hit /usr/libexec/java_home

7. It’ll return the Java installation path as /Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home

8. Copy and past in the file .zshenv as export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home

9. Save Cmd+S and close the file

10. Make sure the file saved by hitting cat ~/.zshenv to see what’s in the file

11. Close the terminal and reopen

12. Hit echo $JAVA_HOME it should return the java path

You have successfully completed JAVA_HOME setup on Mac

Note: If you are setting up on the bash command line use the file ~/.bashprofile

To setup, MAVEN_HOME refer here

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Enable Notifications OK No thanks