Install Node.js on Linux, macOS and Windows

Node.js is one program, node, plus its package manager, npm. Install the pair once, and every lesson of this course runs with the same two commands. There is no compiler to configure and no project to generate: a file and the runtime are enough.

This section is the whole installation part of the course. It names the package for each system, the version the pages were written against, the two commands that prove the install works, and the first program that prints what the runtime is.

Which Node.js this course uses

Node.js publishes two lines at a time. The even-numbered line is the LTS line: it receives fixes for years and is what a server should run. The odd-numbered line is the current line, with the newest language features and a shorter life. This course was written and run on Node.js 24.22.1, which is an LTS release, with npm 11.12.1.

A newer version of the same line runs these programs unchanged. A version older than 20 does not: the course uses node: module names and a few syntax forms that older releases do not parse. Check the number before you start, with the commands in the next section.

Install Node.js

Every way of installing gives the same two programs. A system package is the quickest and is a few releases behind; the installer from the Node.js site is current; a version manager is what you want when several projects need different versions. Pick one, run one command, and open a new terminal so that the PATH change is picked up.

On Linux, use the package manager of the distribution. On Alpine it is apk:

sudo apk add nodejs npm

On Debian and Ubuntu the package is called the same:

sudo apt update
sudo apt install nodejs npm

On Fedora and its relatives:

sudo dnf install nodejs npm

On macOS the package manager is Homebrew:

brew install node

On Windows, the package manager that ships with the system installs the LTS line:

winget install OpenJS.NodeJS.LTS

The official installer for every system is the download page at nodejs.org. It is the same runtime, and on Windows it is the option that needs no package manager at all.

Check the install

Two commands print the two versions. The first is the runtime; the second is the package manager that came with it. If a shell answers command not found, the install directory is not on the PATH yet, and a new terminal is the usual fix.

node --version
npm --version

v24.22.1
11.12.1

The versions matter only as a floor. A program can read the same numbers at run time from process.versions, which is a map of every engine inside the binary: the JavaScript engine, the event loop library, the module system and Node.js itself.

console.log('node:', process.versions.node); console.log('v8:', process.versions.v8); console.log('libuv:', process.versions.uv); console.log('module format:', process.versions.modules); console.log('release:', process.release.name); console.log('platform:', process.platform + '-' + process.arch);

node versions.js

node: 24.22.1
v8: 13.6.233.17-node.58
libuv: 1.52.1
module format: 137
release: node
platform: linux-x64

The modules number is the application binary interface of the module system: a native addon compiled for one number does not load into a runtime with another. The last line is the pair a program usually tests when it must behave differently on another system.

npm, the package manager

npm installs libraries, runs scripts and keeps a lock file that pins the exact version of every dependency. Nothing in this part of the course needs it: the ten lessons use only what the runtime already contains. It is installed now because every JavaScript project on a real machine starts with it, and the lesson on tooling in the last part of the course uses it in full.

One habit is worth taking from the first day: run npm --version in the folder where the work lives, and keep the project package.json beside the files it describes. A program that runs on this machine and nowhere else is almost always a dependency that was installed globally by hand.

Exercises

  1. Install Node.js with the command for your system, open a new terminal and run node --version. Which line of the LTS series did you get?
  2. Change versions.js so that it prints only the major version of Node.js, using split(".")[0]. What does the new line print with your version?
  3. Find the folder where the system package put node, with which node on Linux and macOS or where node on Windows. Is it the same folder as npm?

Questions

A new set of questions in a new order every time. Choose one answer for each, then check.

  1. Which two programs does a Node.js installation provide?

    Answer

    node and npm

    node runs the files, and npm installs packages and runs project scripts.

  2. What does LTS mean for a Node.js release line?

    Answer

    It receives fixes for years and is the line a server should run

    The even-numbered LTS line is maintained for years, while the current line moves faster and lives less.

  3. Which command prints the npm version?

    Answer

    npm -v

    npm -v and npm --version are the same command, and node knows nothing about npm.

  4. Which package manager installs Node.js on macOS in this lesson?

    Answer

    Homebrew

    The command is brew install node; apt and apk belong to Linux, and winget to Windows.

  5. A fresh terminal answers command not found for node after the install. What is the usual cause?

    Answer

    The install directory is not on the PATH of that shell

    The install directory is added to PATH for new shells, and the shell that was already open keeps the old value.

  6. What does process.versions.modules name?

    Answer

    The application binary interface of the module system

    A native addon compiled for one ABI number does not load into a runtime with another.

  7. What does process.release.name print under Node.js?

    Answer

    node

    The release object names the runtime, and under Node.js that name is node.

  8. What does this program print? const [major] = process.versions.node.split("."); console.log(major); with the Node.js of this course?

    Answer

    24

    process.versions.node is 24.22.1 without the leading v, and the first part is 24.

  9. What does node --version print?

    Answer

    v24.22.1

    The command prints a v and the three numbers, while process.version inside a program has the same form.

  10. Why does this part of the course not need npm packages?

    Answer

    Because every lesson uses only the modules that ship with the runtime

    Files, the REPL and the standard modules are enough for these ten lessons; the tooling part comes later.

The code on this page was run with Node.js 24.22.1 and npm 11.12.1 on Alpine Linux 3.24.3 (x86_64) in a Docker container. The install commands for each system were not run on this machine: they belong to a fresh system of that kind.

Article author: Arthur Isaev