TidyURLs
Go to Tools
BLOG
The TidyURLsJournal

Practical guides, tutorials, and insights about URLs, SEO, web development, and online marketing. Learn, troubleshoot, and get the most of the web.

Back to the Journal
TidyURLs Journal

How to Install Node.js and npm on Windows, macOS, and Linux

Practical insights, clear explanations, and useful ideas for understanding the web.

October 25, 20267 min read7 topics
How to Install Node.js and npm on Windows, macOS, and Linux
Explore the details
#Node.js#npm#developer setup#installation guide#Windows#macOS#Linux
October 25, 20267 min read

Installing Node.js gives you the JavaScript runtime used to run programs outside a web browser. It also includes npm, the package manager most Node.js projects use. This guide covers beginner-friendly installation options for Windows, macOS, and Linux, how to check that everything works, and what to try if your terminal cannot find the commands.

Key takeaways

  • For a straightforward setup, download the current LTS installer from the official Node.js website.
  • The official Windows and macOS installers include npm. Linux package-manager installations usually install Node.js and npm together, but check your distribution's package details.
  • Verify your setup with node --version and npm --version.
  • A version manager is useful when different projects require different Node.js versions. Avoid mixing version managers with separate system-wide installations unless you understand how their PATH settings interact.

What are Node.js and npm?

Node.js is a runtime that lets you execute JavaScript on your computer or a server. npm is a package manager commonly used to install libraries and run scripts for Node.js projects. They are separate tools, but npm is bundled with the official Node.js installers.

For most learners, the LTS (Long-Term Support) release is a sensible starting point. It is intended for ongoing use and receives maintenance over time. Choose the version a project requires if its documentation specifies one.

Install Node.js and npm on Windows

Option 1: Use the official installer

  1. Visit nodejs.org/en/download and choose the Windows installer for the LTS release.
  2. Run the downloaded .msi file.
  3. Follow the setup prompts. Keep the option to add Node.js to PATH enabled if it is presented.
  4. Close and reopen your terminal so it can read the updated environment.

The installer normally installs both node and npm.

Option 2: Use a Windows version manager

If you need to switch Node.js versions between projects, you can use a Windows version manager such as nvm-windows, a separate project from the Unix-oriented nvm. Follow its installation instructions, then open a new terminal and run commands such as:

nvm install lts
nvm use lts
node --version
npm --version

Do not assume that nvm-windows and a separate MSI installation will automatically work together. They can compete for which node.exe is found first on PATH. If you switch to a version manager, remove or disable conflicting installations as its documentation recommends.

Install Node.js and npm on macOS

Option 1: Use the official installer

  1. Download the macOS installer for the LTS release from nodejs.org/en/download.
  2. Open the .pkg file and follow the installer prompts.
  3. Open a new Terminal window and verify the installation.

This is a practical choice if you want a single Node.js version and do not already use a package manager or version manager.

Option 2: Use Homebrew

If Homebrew is already part of your setup, you can install its Node.js package with:

brew install node

Homebrew manages its own package version, which may not match a project's required version. Use a version manager instead if you regularly need to switch versions.

Option 3: Use a version manager

A version manager can install and switch between Node.js versions without requiring you to change the system-wide installation for every project. On macOS, nvm is one common option. Install it by following the instructions for the nvm project, then use:

nvm install --lts
nvm use --lts
node --version
npm --version

The exact setup steps depend on your shell and its startup files. Follow the version manager's current instructions rather than copying an installation command from an unrelated guide.

Install Node.js and npm on Linux

Linux installation steps vary by distribution. You can use your distribution's package manager, or use a version manager if you need project-specific versions.

Install through your distribution's package manager

On Debian or Ubuntu, the basic package-manager approach is:

sudo apt update
sudo apt install nodejs npm

On Fedora, you can install Node.js with:

sudo dnf install nodejs

On Arch Linux, install the Node.js and npm packages with:

sudo pacman -S nodejs npm

Package names and versions can differ across distributions and releases. Check your distribution's package documentation, then verify the installed versions. A distribution package may not provide the version a particular project needs.

Use a version manager for multiple project versions

For a development machine where projects require different Node.js versions, a version manager such as nvm can be more convenient than relying on the distribution package. Install it using the project's instructions for your shell, then run:

nvm install --lts
nvm use --lts
node --version
npm --version

On Linux, avoid running version-manager setup commands with sudo unless the tool's instructions specifically require it. A version manager is generally intended to manage Node.js within your user account.

Verify the installation

Open a new terminal window and run:

node --version
npm --version

Each command should print a version number. For example, output beginning with v from node --version indicates that the command ran; the exact version depends on what you installed. To check that Node.js can run a small program, try:

node -e "console.log('Node.js is working')"

If you use a version manager, also check that the selected version matches the project you're working on. Project documentation or a version file in the project may specify a requirement.

Troubleshoot common installation problems

“Command not found” or “not recognized”

Your shell cannot find the executable. Close and reopen the terminal first; installers often update PATH, but an already-open terminal may not see the change. If that does not help, check that the installation completed and that its directory is included in PATH.

To locate the command, try the platform-appropriate check:

# PowerShell
Get-Command node
where.exe node
# macOS or Linux
command -v node
which node

If you find more than one Node.js executable, a previous installation or version manager may be taking precedence. Inspect the result before changing PATH or uninstalling software.

node works, but npm does not

The installation may be incomplete, or your system may package npm separately. Re-run or repair the official installer, or check your distribution's package instructions. If you use a version manager, confirm that a Node.js version is installed and selected in the current shell.

Permission errors while installing packages

Avoid responding to every npm permission error by running npm with administrator or root privileges. That can create files owned by a different account and cause later permission problems. Prefer a version manager, or follow npm's official guidance for your operating system and the specific command that failed.

The version is different from what you expected

Multiple installations may exist, or your version manager may have selected a different release. Check which executable the terminal resolves, then select the intended version using your manager. Also check whether the project specifies a particular Node.js version.

Common mistakes and safer habits

  • Installing an outdated version without checking: A system package can be behind the version a project expects. Verify the version after installation.
  • Mixing installation methods: An MSI installer, a package manager, and a version manager can all put executables on PATH. Choose a primary method and investigate duplicates when the wrong version runs.
  • Forgetting to reopen the terminal: Environment changes may not appear in existing terminal sessions.
  • Using sudo for routine npm commands: Use it only when appropriate for the specific operation; it is not a general fix for permissions.
  • Assuming every project uses the latest version: Follow the project's stated Node.js requirement, especially when working with class materials or an existing codebase.

Conclusion

For a simple setup, install the LTS release from the official Node.js website and confirm that both node --version and npm --version work. If you need different releases for different projects, use a version manager and keep it from conflicting with other Node.js installations. When something fails, check the terminal session, selected executable, and PATH before reinstalling.