My macOS Cheat Sheet

My macOS Cheat Sheet

How to set JAVA_HOME on macOS Monterey?

  1. First check which shell you are using (either bash or zsh). For zsh shell, we can put the environment variables at ~/.zshenv or ~/.zshrc.
    echo $SHELL
    /bin/zsh
    
  2. On Mac OS X 10.5 or later, we can use /usr/libexec/java_home to return the location of the default JDK.

    /usr/libexec/java_home
    /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
    
  3. Or list all installed java versions with -V

    % /usr/libexec/java_home -V
    Matching Java Virtual Machines (3):
     17.0.9 (x86_64) "Oracle Corporation" - "Java SE 17.0.9" /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
     17.0.9 (x86_64) "Oracle Corporation" - "Oracle GraalVM 17.0.9+11.1" /Library/Java/JavaVirtualMachines/graalvm-jdk-17.0.9+11.1/Contents/Home
     11.0.13 (x86_64) "Amazon.com Inc." - "Amazon Corretto 11" /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
    
  4. Open the ~/.zshenv

    nano ~/.zshenv
    
  5. Add the following content
    export JAVA_HOME=$(/usr/libexec/java_home)
    
  6. Source the file and print the $JAVA_HOME, done.
    source ~/.zshenv
    echo $JAVA_HOME
    /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
    

Install node on macOS

Download the package at the official Node Website. The installation paths are as follows:
Node.js

/usr/local/bin/node

npm

/usr/local/bin/npm

Make sure that /usr/local/bin is in your $PATH.