All academies

Installing Node.js

Install Node with nvm, verify versions, and understand LTS.

10 minLevel 2 of 20

Ways to install Node.js

There are three common ways to get Node.js on your machine:

  • Official installer from nodejs.org — simple, but locks you to one version
  • A version manager like nvm (macOS/Linux) or nvm-windows — lets you install and switch between multiple versions
  • A system package manager like Homebrew, apt, or winget — convenient but often lags behind releases

For developers, a version manager is the recommended choice. Different projects often require different Node versions, and a version manager makes switching a one-line command instead of a reinstall.

Installing nvm (macOS / Linux)
# Install nvm with the official install script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

# Restart your terminal, then verify:
nvm --version

Installing and switching versions with nvm

Once nvm is installed, managing Node versions becomes trivial. You can install the latest LTS release, a specific version, or the newest Current release, and switch between them per terminal session.

A project can also pin its Node version in a .nvmrc file containing just a version number (like 20). Anyone who clones the project runs nvm use and gets the right version automatically.

Everyday nvm commands
nvm install --lts     # install the latest LTS release
nvm install 20        # install the newest 20.x release
nvm use 20            # switch this terminal to Node 20
nvm ls                # list installed versions
nvm alias default 20  # make Node 20 the default for new terminals

LTS vs Current: which version to pick

Node.js ships two release lines at any time:

  • LTS (Long Term Support) — even-numbered majors (18, 20, 22). Each LTS line receives bug and security fixes for about 30 months. This is what you should use for real projects and production servers.
  • Current — the newest major, including odd-numbered releases. It gets new features first but has a short support window.

Rule of thumb: use the latest LTS unless you specifically need a bleeding-edge feature. Production systems running odd-numbered versions stop receiving security patches quickly.

Verifying your installation

After installing, confirm that both node and npm are available. npm is bundled with Node.js — installing Node gives you npm automatically, so there is nothing extra to install.

If node -v prints a version number, you are ready. If the command is not found, your shell's PATH probably does not include the install location — with nvm, restarting the terminal usually fixes it.

Check versions
node -v    # e.g. v20.11.0
npm -v     # e.g. 10.2.4

# Run a one-liner without creating a file:
node -e "console.log('Node works!')"

Your environment, from inside Node

Once Node is installed, programs can inspect their own environment. The process object exposes the working directory, command-line arguments, and environment variables — you'll use all of these constantly in later lessons.

Hello from an installed Node
// Things any freshly installed Node can tell you:
console.log("Working directory:", process.cwd());
console.log("Script arguments:", process.argv.slice(2));

const os = require("os");
console.log("Platform:", os.platform());
console.log("CPU cores:", os.cpus().length);

Check your understanding

5 questions

Question 1 of 5

Score: 0

Multiple choice

Why is a version manager like nvm recommended over the official installer?