This is the easiest way to get Node.js up and running, and it generally handles the path configuration for you.
-
Download the LTS Installer:
- Open your web browser and go to the official Node.js website: https://nodejs.org/en/download/
- You will see two main download options: "LTS" (Long Term Support) and "Current." Click on the "LTS" button. This will typically download the latest LTS version, which will be Node.js 22+ at the time of this writing.
- Select the macOS Installer (.pkg).
-
Run the Installer:
- Once the
.pkg
file is downloaded, locate it in your Downloads folder and double-click it to start the installation process. - Follow the on-screen prompts. You can generally accept the default installation location, as this usually places Node.js in a standard system path that is already configured.
- Enter your macOS password when prompted to authorize the installation.
- Once the
-
Verify the Installation:
- Open your Terminal application (you can find it in Applications/Utilities, or by searching with Spotlight).
- Type the following command and press Enter:
node -v
- You should see the installed Node.js version (e.g.,
v22.x.x
). - To verify npm (Node Package Manager), which is installed alongside Node.js, type:
npm -v
- You should see the installed npm version.
Path Configuration (Usually Automatic with Installer):
The official Node.js installer typically handles adding Node.js to your system's PATH
environment variable. This means you usually don't need to manually set it. However, if after verifying the installation, the node -v
or npm -v
commands don't work (e.g., you get "command not found"), you might need to ensure the path is correctly set.
How to check and potentially add the path (if needed):
Your macOS typically uses zsh
as its default shell. The configuration file for zsh
is ~/.zshrc
.
-
Check your current PATH:
- In your Terminal, type:
echo $PATH
- Look for
/usr/local/bin
or a path related to Node.js (e.g.,/opt/homebrew/bin
if you used Homebrew for other installations). The Node.js installer usually places the executables in/usr/local/bin
, which is typically already in yourPATH
.
- In your Terminal, type:
-
Add to PATH (if necessary):
- If you don't see
/usr/local/bin
in yourPATH
or Node.js commands are not found, you can add it manually. - Open your
~/.zshrc
file in a text editor. You can usenano
in the Terminal:nano ~/.zshrc
- Add the following line to the end of the file:
export PATH="/usr/local/bin:$PATH"
- Note: If you installed using Homebrew, the path might be
/opt/homebrew/bin
. If so, useexport PATH="/opt/homebrew/bin:$PATH"
.
- Note: If you installed using Homebrew, the path might be
- Press
Control + X
, thenY
to save, andEnter
to confirm the filename. - Apply the changes: Close your current Terminal window and open a new one, or run:
source ~/.zshrc
- Now, try
node -v
andnpm -v
again. They should work.
- If you don't see