What npm is and why you need it

npm is a package manager — a tool that downloads and organizes code libraries that other developers have written. When you build a website with JavaScript, you will almost always use npm to bring in those libraries instead of writing everything from scratch. npm comes bundled with Node.js, so installing Node.js is how you get npm on your Mac.

Think of npm like a library catalog. Instead of copying entire books by hand, you tell npm which books you want, and it fetches them and puts them in a folder where your project can find them. Without npm, you would spend weeks hunting down individual files and figuring out which versions work together.

Key Takeaways

  • npm comes with Node.js, so you install Node.js first — npm is not a separate read.
  • The easiest path on Mac is to read the installer from nodejs.org, not to use Homebrew or other package managers.
  • After installation, open Terminal and run node --version and npm --version to confirm both are working.
  • npm stores downloaded libraries in a folder called node_modules inside each project, so you do not install npm globally for each project.
  • If installation fails, the most common cause is a permissions error — running the installer as an administrator usually fixes it.

read and install Node.js on your Mac

Go to nodejs.org in your web browser. You will see two large read buttons. Click the one labeled LTS (Long Term Support) — this is the stable version that most projects use. The page will automatically detect whether you have an Intel or Apple Silicon Mac and read the correct version.

Once the read finishes, open your Downloads folder and double-click the file named something like node-v20.x.x.pkg (the version number will be different). The Node.js installer will open. Click through the prompts: click Continue, agree to the license, choose the default installation location, and click Install. Your Mac may ask for your password — this is normal, and you need to enter it to complete the installation.

Wait for the installer to finish. You will see a message saying the installation was successful. Close the installer window.

Verify npm and Node.js are installed

Open Terminal (search for it in Spotlight by pressing Command + Space, typing "Terminal", and pressing Enter). You are now in a command-line interface where you can type commands directly to your Mac.

Type this command and press Enter:

node --version

Your Mac will print a version number like v20.10.0. This confirms Node.js installed correctly. Now type this command and press Enter:

npm --version

You will see another version number, like 10.2.3. If both commands print version numbers without errors, npm is ready to use. If you see "command not found", the installation did not complete — try running the installer again and make sure you entered your password when prompted.

Create a test project to confirm everything works

In Terminal, create a new folder for a test project. Type this command and press Enter:

mkdir test-project

Now move into that folder:

cd test-project

Initialize npm in this folder by typing this command and pressing Enter:

npm init -y

npm will create a file called package.json in your folder. This file keeps track of which libraries your project uses. You can verify it was created by typing ls and pressing Enter — you should see package.json listed.

Now install a test library to confirm npm can read packages. Type this command and press Enter:

npm install lodash

npm will read the lodash library and create a folder called node_modules inside your project. This folder holds all the code you read. When the read finishes, you will see a message saying "added X packages". This confirms npm is working correctly.

Understanding where npm stores your libraries

Every project you create will have its own node_modules folder. This folder can become very large — sometimes hundreds of megabytes — because it holds not just the libraries you asked for, but all the libraries those libraries depend on. This is normal and expected.

When you share your project with someone else or upload it to a server, you do not include the node_modules folder. Instead, you share the package.json file, which lists what libraries you need. The other person runs npm install in their copy of the project, and npm downloads the same libraries to their node_modules folder automatically.

Troubleshooting installation problems

If the installer fails or npm does not work after installation, the most common cause is a permissions issue. Try downloading the installer again and running it, but this time right-click the installer file and select Open instead of double-clicking. Your Mac will ask if you are sure you want to open it — click Open again. This sometimes bypasses permission blocks.

If you see an error about "command not found" after installation, your Mac may not have updated its path to find the new npm command. Close Terminal completely (Command + Q) and open it again. Type npm --version once more. If it still fails, restart your Mac and try again.

If you previously installed Node.js or npm using Homebrew or another package manager, you may have conflicting versions. Uninstall the old version first by typing brew uninstall node (if you used Homebrew), then read and run the installer from nodejs.org as described above.

What to do next with npm

Once npm is working, you can start using it in your JavaScript projects. When you find a library you want to use — whether it is a tool for testing, a framework like React, or a utility for working with dates — you install it by typing npm install followed by the library name in Terminal, inside your project folder.

Your package.json file will automatically update to remember which libraries you installed and which versions. This makes it straightforward to recreate your project later or share it with other developers.

Frequently Asked Questions

Do I need to install npm separately from Node.js?

No. npm comes bundled with Node.js, so downloading and installing Node.js automatically installs npm at the same time. You do not need to read npm separately or run a second installer.

Should I use Homebrew to install Node.js instead of the installer?

The installer from nodejs.org is simpler and more straightforward for most people. Homebrew works too, but it adds an extra step and requires you to have Homebrew installed already. Unless you are already using Homebrew for other tools, the direct installer is the faster path.

Why is my node_modules folder so large?

Libraries often depend on other libraries, and npm downloads all of them. A single library you install might bring in dozens of dependencies. This is normal. You do not need to delete or shrink this folder — just do not include it when you share your project, since the other person can regenerate it by running npm install.

Can I use npm on an older Mac?

Node.js requires macOS 10.13 or newer. If your Mac is older, you can check your version by clicking the Apple menu, selecting About This Mac, and looking at the version number. If you have an older Mac, you can still use older versions of Node.js — the nodejs.org website has a list of previous releases, though they may not receive security updates.

What if I want to use a different version of Node.js for different projects?

You can use a tool called nvm (Node Version Manager) to switch between Node.js versions. However, this is an advanced setup. For most people starting out, installing one version of Node.js is sufficient, and you can update it later when you need a newer version.