What npm is and why you need it

npm is a package manager — a tool that downloads and organizes code libraries that other people have written. When you write JavaScript, you will often need code from other developers to do common tasks like format dates, validate forms, or build interactive features. npm fetches that code for you and keeps it organized in your project folder.

npm comes bundled with Node.js, which is a runtime environment that lets JavaScript run outside the browser. You cannot install npm by itself — you install Node.js, and npm comes along automatically. Once npm is installed, you can use it from your command line to download libraries and manage your JavaScript projects.

Key Takeaways

  • npm is included with Node.js, so you install Node.js first and npm comes automatically.
  • Download the Node.js installer from nodejs.org, choose the LTS (Long Term Support) version, and run the installer on your computer.
  • After installation, open your command line and type npm --version to confirm npm is working.
  • Once npm is installed, you can use the command npm install inside a project folder to download code libraries your project needs.
  • Different operating systems (Windows, Mac, Linux) have slightly different installation steps, but the process is straightforward on all of them.

Download Node.js from the official website

Go to nodejs.org in your web browser. You will see two large download buttons. Choose the LTS version, which stands for Long Term Support. LTS versions are stable and receive updates for longer, making them the right choice for learning and for projects you plan to keep using. The other option, Current, has the newest features but changes more often.

The website detects your operating system automatically and shows you the right installer. If it does not, look for a dropdown menu or link that lets you choose Windows, macOS, or Linux. Download the installer file to your computer — it will be named something like node-v20.10.0-x64.msi on Windows or node-v20.10.0.pkg on Mac.

Run the installer on Windows

Find the installer file you downloaded (usually in your Downloads folder) and double-click it. A window will open asking you to accept the license agreement — read it if you want, then click the checkbox and click Next. The installer will ask you where to put Node.js on your computer; the default location is fine, so click Next again.

On the next screen, you will see options for what to install. Leave all the checkboxes checked — you want Node.js, npm, and the tools that let you run Node.js from your command line. Click Next, then click Install. Windows may ask for permission to make changes to your computer; click Yes. When the installation finishes, click Finish and restart your computer.

Run the installer on Mac

Find the installer file you downloaded and double-click it. A window will open showing the Node.js installer package. Double-click the package icon inside. The installer will ask for your Mac password — this is normal, because the installer needs permission to put files in system folders. Type your password and click Install Software.

The installer will run for a minute or two. When it finishes, click Close. You do not need to restart your Mac, but you do need to close and reopen your Terminal window if you have one open, so that Terminal picks up the new npm command.

Verify npm is installed and working

Open your command line. On Windows, search for Command Prompt or PowerShell in the Start menu and click it. On Mac or Linux, open Terminal (search for it in Spotlight or Applications). A black or white window will open with a blinking cursor.

Type this command and press Enter:

npm --version

npm will print a version number, like 10.2.4. If you see a version number, npm is installed and working. If you see an error message saying npm is not found, restart your computer and try again — sometimes the command line needs a restart to recognize the new software.

Use npm to install packages in your project

Once npm is working, you can use it to download code libraries. First, create a folder for your project or open an existing one. Open your command line and navigate to that folder by typing cd followed by the path to your folder. For example: cd Documents/my-project.

Inside your project folder, type npm install package-name, replacing package-name with the name of the library you want. For example, npm install lodash downloads a popular utility library. npm will create a folder called node_modules in your project and put the library there. It will also create or update a file called package.json that keeps track of which libraries your project uses.

You only need to install Node.js and npm once on your computer. After that, every project folder can use npm to download the libraries it needs.

Troubleshooting common installation problems

If the installer will not run on Windows, try right-clicking the installer file and choosing "Run as administrator." If you get a message about your antivirus software blocking the installer, temporarily disable it or add the installer to your antivirus exceptions list, then try again.

If npm still does not work after restarting, your system PATH (the list of places your computer looks for commands) may not have been updated. On Windows, try uninstalling Node.js completely, restarting your computer, and installing again. On Mac, try closing Terminal completely and opening a new Terminal window. If you are still stuck, try installing Node.js using a package manager like Homebrew on Mac or Chocolatey on Windows — these tools handle PATH updates automatically.

Frequently Asked Questions

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

No. npm comes automatically when you install Node.js. You cannot install npm alone. If you want npm, download and install Node.js, and npm will be there.

What is the difference between LTS and Current versions?

LTS (Long Term Support) versions are stable and receive security updates for years. Current versions have the newest features but change more often. For learning and most projects, LTS is the better choice.

Can I have multiple versions of Node.js on my computer?

Yes, but it requires extra tools like nvm (Node Version Manager) on Mac and Linux, or nvm-windows on Windows. For most people starting out, one version is enough. You can always uninstall and reinstall a different version later if you need to.

What does npm install actually do?

When you type npm install package-name, npm downloads that package from the npm registry (a central library of code) and puts it in a node_modules folder in your project. It also records the package name and version in your package.json file so you remember what your project depends on.

Why do I see a package.json file in my project?

npm creates package.json automatically to track which packages your project uses and what versions. This file lets other people (or you on another computer) run npm install with no arguments, and npm will download all the packages listed in that file.