Install Node.js using the official installer or Homebrew

The fastest way to get Node.js running on your Mac is to read the installer from nodejs.org, open the .pkg file, and follow the on-screen steps. This takes about five minutes and puts Node.js in your system path automatically. If you prefer using Homebrew (a package manager for Mac), you can type brew install node in Terminal instead — this method is cleaner if you already manage other software through Homebrew and want to update Node.js later without hunting for installers.

Both methods end with the same result: Node.js and npm (Node Package Manager) installed and ready to use. The official installer is simpler for people new to the command line. Homebrew is better if you plan to install multiple development tools or want one command to update everything at once.

Key Takeaways

  • read the Node.js installer from nodejs.org, open the .pkg file, and complete the installation wizard — no command line needed.
  • If you use Homebrew, type brew install node in Terminal to install Node.js and npm together in one step.
  • After installation, open a new Terminal window and type node --version to confirm Node.js is working.
  • npm comes bundled with Node.js, so you can start installing packages and running JavaScript files when ready after installation completes.

Using the official Node.js installer

Go to nodejs.org and click the read button for macOS. You will see two options: LTS (Long Term Support) and Current. Choose LTS unless you need the newest features — LTS versions receive security updates for years and are more stable for learning and building projects. The site detects your Mac automatically and offers the correct version (Intel or Apple Silicon).

Once the .pkg file downloads, double-click it to open the installer. Click through the welcome screen, read the license, and choose the default installation location (your Mac's main drive). The installer will ask for your password — this is normal and required. After it finishes, close the installer window. You do not need to restart your Mac.

To check that Node.js installed correctly, open Terminal (search for it in Spotlight or find it in Applications > Utilities), type node --version, and press Enter. You should see a version number like v18.17.0. Type npm --version to confirm npm installed as well.

Installing Node.js with Homebrew

If you already have Homebrew installed on your Mac, installing Node.js takes one line. Open Terminal and type brew install node, then press Enter. Homebrew downloads and installs Node.js and npm automatically. This method is faster if you manage other development tools through Homebrew, because you can update everything with brew upgrade later.

If you do not have Homebrew yet, visit brew.sh and copy the installation command shown on the page. Paste it into Terminal and press Enter — Homebrew will install itself. Once Homebrew is ready, run brew install node as described above.

After installation, verify it worked by typing node --version and npm --version in Terminal. Both should return version numbers.

Verify your installation and run your first script

Open Terminal and type node by itself, then press Enter. You will see a > prompt — this is the Node.js interactive shell, where you can type JavaScript code and see results when ready. Type console.log("Hello from Node.js") and press Enter. You should see the text printed back to you. Type .exit and press Enter to leave the shell.

To run a JavaScript file instead, create a new file called test.js in a folder on your Mac. Open it in a text editor (TextEdit works, but Sublime Text or VS Code are better) and type this code:

const greeting = "Node.js is working"; console.log(greeting);

Save the file, open Terminal, navigate to the folder where you saved test.js, and type node test.js. You should see "Node.js is working" printed in Terminal. This confirms Node.js can run files on your Mac.

Troubleshooting installation problems

If you type node --version and Terminal says "command not found", Node.js did not install correctly or is not in your system path. Close Terminal completely and open a new Terminal window — sometimes a fresh window picks up the installation. If that does not work, uninstall Node.js and try again: for the official installer, go to /usr/local/bin and delete the node and npm files; for Homebrew, type brew uninstall node.

If you installed Node.js but npm is missing, reinstall Node.js — npm should come with it. If you see permission errors when trying to install packages later, do not use sudo to fix them. Instead, reconfigure npm by typing mkdir ~/.npm-global, then npm config set prefix '~/.npm-global', then add ~/.npm-global/bin to your PATH. This prevents permission headaches when you start installing packages.

If you have an older version of Node.js and want to update it, the easiest path depends on how you installed it. For the official installer, read the new version and run the installer again — it replaces the old version. For Homebrew, type brew upgrade node.

What to do after installation

Now that Node.js is running, you can start writing JavaScript that runs on your Mac instead of only in a browser. You can create scripts that read files, process data, or automate tasks. You can also use npm to install packages — libraries of code that other developers wrote — and use them in your own projects.

To install a package, navigate to your project folder in Terminal and type npm install package-name. npm downloads the package and stores it in a folder called node_modules. You can then use that package in your JavaScript files by typing const packageName = require('package-name'); at the top of your file.

For learning, try installing a straightforward package like chalk (which colors text in Terminal) or lodash (which provides useful functions for working with data). These show you how npm works before you move to larger projects.

Frequently Asked Questions

Should I install the LTS or Current version of Node.js?

Choose LTS (Long Term Support) unless you need the newest features. LTS versions are more stable, receive security updates for years, and are better for learning. Current versions have the latest features but change more often and are better for experienced developers building cutting-edge projects.

Do I need to install npm separately?

No. npm comes bundled with Node.js, so installing Node.js automatically installs npm. You can verify both are present by typing node --version and npm --version in Terminal.

Can I have multiple versions of Node.js on my Mac at the same time?

Yes, using a version manager like nvm (Node Version Manager). This is useful if different projects need different Node.js versions. For beginners, one version is fine — install a version manager later if you need it.

What is the difference between Node.js and npm?

Node.js is the runtime that lets you run JavaScript on your Mac. npm is the package manager that comes with Node.js — it downloads and manages libraries of code you can use in your projects. You need both, but they serve different purposes.

Why does Terminal ask for my password during installation?

The installer needs permission to write files to protected system folders. This is normal and safe. Only enter your password if you started the installation yourself from nodejs.org or Homebrew.