Installing Node.js and NPM

Learn how to install Node.js and NPM step by step on Windows, macOS, and Linux. Get started building scalable JavaScript applications by setting up your development environment quickly and easily.

Published on 20 April 2026
Reading Time 4
Number of Words 843

Installing Node.js and NPM

In 2025, Node.js and NPM remain foundational tools for JavaScript and full-stack development.

Even though many guides exist, it's good to have a modern, up-to-date walkthrough.

This article covers how to install Node.js and NPM across platforms (Windows, macOS, Linux), best practices (using version managers), and examples to verify things work correctly.

What are Node.js and NPM?

  • Node.js is a JavaScript runtime built on Chrome’s V8 engine, allowing you to run JavaScript on the server or outside the browser.

  • NPM (Node Package Manager) is the default package manager for Node.js. It helps you install, version, and manage dependencies for your projects.

When you install Node.js, NPM typically comes bundled with it.

Why use a version manager (strongly recommended)

When working on real-world projects, you might need different versions of Node.js (for different projects, dependencies, or compatibility). Instead of installing/uninstalling versions manually, it's better to use a version manager (e.g. nvm, nvm-windows, n, etc.) to switch easily.

The official NPM documentation now strongly recommends using a version manager for installing Node.js and NPM, rather than a global installer, to avoid permission and conflicts issues.

Step 1: Check if Node.js / NPM is already installed

Open a terminal (shell) and run. CMD in Windows:

node -v npm -v

  • node -v prints the Node.js version.

  • npm -v prints the NPM version.

If both commands output version numbers (e.g. v20.17.0, 9.8.0), you already have them installed.
If the command is not found, or gives an error, you’ll need to install.

Step 2: Choose your installation method

There are two main approaches:

  1. Using a version manager (recommended)

  2. Using a system installer or package manager

I’ll cover both.

A. Using a version manager

On macOS / Linux / WSL (Windows Subsystem for Linux):

  • Use nvm (Node Version Manager).
    Example installation command:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.6/install.sh | bash

    (You may want to check the official GitHub repo for the latest version.) After installation, restart your shell or source your profile (e.g. source ~/.bashrc or source ~/.zshrc). Then:

    nvm install --lts # install the Long-Term Support version nvm use --lts # switch to it

    You can also install specific versions:

    nvm install 20.0.0 nvm use 20.0.0

  • Another tool is n. But nvm is more widely used and flexible for switching versions.

On Windows (native):

  • Use nvm-windows (a version manager for Windows). Official Microsoft docs also mention this as a recommended approach.

  • After installing nvm-windows, you can install a version:

    nvm install lts nvm use lts

Advantages of version managers:

  • You can have multiple Node versions side by side.

  • Easy switching between versions.

  • Avoids messing up global installs and permissions.

B. Using system installers or package managers

If you prefer simplicity and don't need multiple versions, you can use installers or OS package managers.

  • Windows Installer (.msi)
    Download from the official Node.js site. The installer includes Node.js, NPM, and typically adds them to your PATH.
    The installer may also prompt to install tools for native module compilation.

  • macOS Installer (.pkg)
    Similar process: download, run, walk through prompts.

  • Linux / Debian / Ubuntu (via package manager or NodeSource):
    Example using NodeSource:

    curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs

    Or use your distro package manager (though sometimes distro versions lag).

  • Windows via Chocolatey (Windows package manager):

    choco install nodejs-lts refreshenv

    Then verify.

Step 3: Verify the installation & test Node

After installation, run:

node -v npm -v

You should see version numbers. For example:

$ node -v v20.17.0 $ npm -v 9.8.0

If npm is not found, check that it's in your system’s PATH or you may need to close and reopen your terminal.

Example: Create a “Hello World” file

Create a file named hello.js with contents:

console.log("Hello, Node.js is working!");

Then run it:

node hello.js

You should see:

Hello, Node.js is working!

That confirms Node is running correctly.

Step 4: Update NPM (if desired)

Even though NPM is bundled, you may want the latest NPM features. You can update NPM globally:

npm install -g npm@latest

Then check again:

npm -v

Be cautious: sometimes updating globally can lead to version mismatches with Node. Using version managers helps avoid these issues.

Common issues & troubleshooting

  • Permission errors (especially on macOS/Linux):
    Avoid running npm install -g with sudo. Instead, using nvm or allowing NPM to use user-level directories is safer.

  • Conflicting installations:
    If you previously installed Node via another method (e.g. package manager, system installer), remove/uninstall it before using version managers to avoid conflicts. Microsoft’s docs cautions this for Windows.

  • PATH not updated:
    After installing, sometimes you must restart your terminal or refresh the PATH so node and npm are found.

  • Native modules failing to build:
    Some NPM packages include native (C/C++) components. To compile them, you may need build tools (e.g. on Windows: Visual Studio Build Tools, on macOS: Xcode command line tools). Many installers optionally include this.

Example workflow (macOS / Linux) with version manager

Here’s a complete example you can follow:

# Install nvm (check for latest version first)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.6/install.sh | bash

# Reload shell
source ~/.bashrc   # or ~/.zshrc

# Install LTS version of Node
nvm install --lts

# Use it
nvm use --lts

# Check versions
node -v     # e.g. v20.17.0
npm -v      # e.g. 9.8.0

# Create test file
echo 'console.log("Node works!")' > test.js
node test.js   # prints “Node works!”

# Optionally update npm
npm install -g npm@latest
npm -v

Next steps

You’ve now installed Node.js and NPM (or prepared your environment to manage versions). From here, you can:

  • Initialize a project with npm init (or npm init -y) to create a package.json.

  • Install dependencies using npm install <package> or npm install <package> --save-dev.

  • Explore frameworks like Express, Next.js, or integrate with front-end tooling.