Skip to content
Commitpedia
Log in Join & edit

Install Node.js on Linux, macOS and Windows

Get Node.js and npm on any desktop OS. Use a version manager (nvm or fnm) when you work on several projects, or the official installer when you just need one current LTS release.

Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?

Edit history of Install Node.js on Linux, macOS and Windows: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
3 min

Which option to pick

Node.js releases a new major version every six months and projects often pin different ones, so most developers install it through a version manager that can switch per project: nvm is the long-standing choice on Linux and macOS, fnm is a faster alternative that also works natively on Windows. If you only ever need one version, the official installer or your OS package manager is simpler. Avoid the Node.js packages in Debian and Ubuntu’s default repositories: they are usually several majors old. Always pick an LTS (long-term support) release unless a project tells you otherwise.

Step: Linux

With nvm, which installs into your home directory and needs no root:

Check before you run this

  • Downloads a file and runs it straight away. Open the URL and read the script first.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh | bash
source ~/.bashrc
nvm install --lts
nvm use --lts

The installer appends a few lines to your shell startup file (.bashrc, .zshrc or .profile); open a new terminal or source the file so nvm is found. Replace v0.40.8 with the version shown in the nvm README if it is newer.

With fnm:

Check before you run this

  • Downloads a file and runs it straight away. Open the URL and read the script first.
curl -fsSL https://fnm.vercel.app/install | bash
source ~/.bashrc
fnm install --lts
fnm use lts-latest

Without a version manager, the official binary tarball from nodejs.org/en/download works on any distribution; unpack it and add its bin directory to your PATH. For apt-based systems that need a system-wide install, the download page also lists NodeSource repositories.

Step: macOS

brew install fnm
echo 'eval "$(fnm env --use-on-cd --shell zsh)"' >> ~/.zshrc
source ~/.zshrc
fnm install --lts
fnm use lts-latest

The nvm script from the Linux step also works on macOS. For a single fixed version, brew install node installs the current release and brew install node@22 a specific LTS line, or download the .pkg installer from nodejs.org.

Step: Windows

In PowerShell, the official installer via winget:

winget install OpenJS.NodeJS.LTS

Or with fnm as a version manager:

winget install Schniz.fnm
notepad $PROFILE

Add this line to the profile file that opened, save it, then start a new PowerShell window:

fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression
fnm install --lts
fnm use lts-latest

If PowerShell refuses to load the profile, allow local scripts once with Set-ExecutionPolicy -Scope CurrentUser RemoteSigned. nvm itself does not run on Windows; the separate project nvm-windows exists but is unrelated to nvm.

Check it works

node --version
npm --version
node -e "console.log('hello from node')"

You should see a version such as v22.x.x for Node and 10.x.x for npm. To pin a version for a project, create a .nvmrc or .node-version file containing the version; both nvm and fnm read it.

Common problems

  • nvm: command not found right after installing: the shell has not reloaded its startup file. Open a new terminal.
  • node works but npm install -g asks for sudo: you are using a system-wide Node. With nvm or fnm, global packages go into your home directory and no sudo is needed.
  • Old version from apt install nodejs: remove it with sudo apt remove nodejs and use one of the methods above.
  • On Windows, node is not recognised after the installer: close and reopen the terminal so the updated PATH is picked up.

Official documentation

Did this work for you?

No votes yet. Be the first.

If it did not work, the report form below tells the editors what went wrong.

See also

  • 0021 Read and write files in Node.js with fs/promises A complete Node script that walks a folder, reads text files, and writes a JSON report safely, showing the everyday fs/promises calls… Beginner · Step by step · Any system Script Node.js 15 Oct 2026
  • 0022 Build a small Node.js CLI with util.parseArgs A complete, dependency-free command-line tool in Node: options and flags with parseArgs, input from files or a pipe, help text, and meaningful… Intermediate · Step by step · Any system Script Node.js 15 Oct 2026
  • 0027 Fix: SyntaxError: Cannot use import statement outside a module The file uses ES module import syntax, but Node or the browser is loading it as a classic script or CommonJS. Tell… Intermediate · Fixes an error · Any system Article Common errors · Node.js 15 Oct 2026
  • 0263 Build a notes REST API with plain Node.js: CRUD, validation, status codes and CORS Write a small JSON API for notes using only Node.js built-ins: create, read, update and delete, input validation, correct HTTP status codes,… Intermediate · Guided project · Any system Article Making requests · Node.js · Status codes 15 Oct 2026
  • 0319 Fix: npm ERR! EACCES permission denied npm cannot write to a directory it needs: the global install location, its cache in ~/.npm, or a node_modules owned by root.… Beginner · Fixes an error · Linux, macOS Article Common errors · Node.js 15 Oct 2026
  • 0320 Fix: address already in use (EADDRINUSE) Something is already listening on the port your program wants. Find the process with lsof or ss, stop it or pick another… Beginner · Fixes an error · Linux, macOS Article Networking & firewalls · Node.js · Processes & ports 15 Oct 2026

Repos in the wild

  • Node.js nodejs/node The source of the Node.js runtime: a JavaScript engine (V8) plus APIs for files, networking, processes and more, used to run JavaScript outside the browser. GitHub
  • Express (expressjs/express) expressjs/express A minimal and flexible web framework for Node.js, built around routes and middleware, and the foundation of countless APIs and other frameworks. GitHub

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Dominik +3,441 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?