A Step-by-Step Guide to Installing Node.js on macOS
Need Node.js on your Mac? You've got two solid options: the official installer for simplicity, or Homebrew for flexibility. Here's how to get it set up right, step by step.
Jamie
LogicCore Digital
So you're setting up a development environment on macOS and you need Node.js. Good news - installing it on a Mac is pretty straightforward. You've got two main paths: the official installer (simple, works for everyone) or Homebrew (preferred by most developers). Both get you Node.js and npm, but Homebrew gives you more flexibility if you're doing serious development work.
Let's walk through both methods so you can pick what works best for you.
What You'll Need
Before we dive in, make sure you've got these basics covered:
- macOS: A reasonably recent version (macOS 10.15 Catalina or newer is generally recommended for the latest Node.js versions, though older macOS versions might support older Node.js releases).
- Terminal Access: You'll need to be comfortable using the Terminal app (found in
/Applications/Utilities/). Basic command-line knowledge helps. - Internet Connection: You'll be downloading Node.js, so a stable connection is essential.
(Optional but Recommended) Xcode Command Line Tools: Some Node.js packages might need to compile code during installation. Having the Xcode Command Line Tools installed can prevent potential headaches. You can install them by opening Terminal and running:
xcode-select --installFollow the on-screen prompts if they appear. If they're already installed, it'll let you know.
Method 1: Using the Official Node.js Installer
This is the simplest method - just download a standard macOS installer package (.pkg) and run it. Perfect if you want to get up and running quickly without dealing with package managers.
Step 1: Download the Installer
- Open your web browser and head to the official Node.js website: https://nodejs.org/
- On the homepage, you'll typically see two download buttons:
- LTS (Long-Term Support): Recommended for most users. It's stable and supported for a longer period.
- Current: Includes the latest features but might be less stable than LTS.
- Click the LTS button to download the macOS Installer (
.pkg) file.
Step 2: Run the Installer Package
- Find the downloaded
.pkgfile (usually in yourDownloadsfolder). - Double-click it to launch the Node.js installer wizard.
Step 3: Follow the Installation Wizard
- Click through the installer screens by clicking "Continue".
- Agree to the software license agreement.
- Choose the installation location (the default is usually fine).
- Click "Install". You may be prompted to enter your administrator password to authorize the installation.
- Once installation completes, you'll see a confirmation screen. Click "Close".
Step 4: Verify the Installation
- Open the Terminal application (if it's not already open).
Check the installed npm version (npm is installed automatically with Node.js):
npm -vThis should output the corresponding npm version (e.g., 10.2.4).
Check the installed Node.js version:
node -vThis should output the version number you just installed (e.g., v20.11.1).
If both commands display version numbers, Node.js has been successfully installed using the official installer.
Method 2: Using Homebrew (Recommended for Developers)
Homebrew is a popular package manager for macOS that makes installing and managing software a breeze. If you're doing development work, this is often the preferred method because it's easier to update, manage, and switch between versions.
Step 1: Install Homebrew (If Not Already Installed)
- Open the Terminal application.
- Check if Homebrew is already installed by typing:
brew --versionIf it's installed, you'll see a version number. If not, you'll get a "command not found" error.
If Homebrew isn't installed, paste the following command into your Terminal and press Enter. This command comes from the official Homebrew website (https://brew.sh/):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Follow the on-screen instructions. It might ask for your password and prompt you to install the Xcode Command Line Tools if you haven't already.
Step 2: Update Homebrew
It's good practice to make sure Homebrew is up-to-date before installing new packages. Run this in Terminal:
brew updateStep 3: Install Node.js
Now install Node.js using Homebrew:
brew install nodeHomebrew will download and install the latest stable version of Node.js and npm.
Step 4: Verify the Installation
- Open a new Terminal window or tab (this ensures your shell recognizes the newly installed commands).
Check the npm version:
npm -vCheck the Node.js version:
node -vIf both commands display version numbers, Node.js has been successfully installed using Homebrew.
You're All Set
That's it! You've got Node.js and npm installed on your macOS computer using either the official installer or Homebrew. You're ready to start using Node.js for your projects, run JavaScript files from the command line, and manage project dependencies with npm.
Helpful Resources
Want to dive deeper? These official resources are worth bookmarking:
- Node.js Official Site: https://nodejs.org/
- Node.js Installation Guides (Official): https://nodejs.org/en/download/package-manager
- npm Documentation: https://docs.npmjs.com/
- Homebrew Website: https://brew.sh/
- (Advanced) NVM (Node Version Manager) - For managing multiple Node.js versions: https://github.com/nvm-sh/nvm