Installing Node & nvm

Install Node.js directly or manage multiple versions with nvm.

Syntaxnvm install --lts nvm use --lts

To use Node.js you need to install it. There are two common ways:

1. Direct install

Download the LTS (Long Term Support) version from nodejs.org. LTS releases are the most stable choice for real projects.

2. Node Version Manager (nvm)

nvm lets you install and switch between multiple Node versions — useful when different projects need different versions.

After installing, check that Node and npm are available by printing their versions.

Example

Example · bash
# Install nvm, then install and use the latest LTS Node
nvm install --lts
nvm use --lts

# Verify the install
node --version   # e.g. v20.11.1
npm --version    # e.g. 10.2.4

When to use it

  • A new team member installs nvm to quickly switch between the LTS version required by the legacy project and the current version for a new microservice.
  • A CI pipeline uses a `.nvmrc` file so every build agent automatically picks up the correct Node version without manual configuration.
  • A developer on Windows installs Node via the official MSI installer to get both `node` and `npm` in one step for a course project.

More examples

Verify Node installation

Confirms that both Node.js and npm were installed correctly and prints their versions.

Example · bash
node --version   # e.g. v22.2.0
npm --version    # e.g. 10.7.0

Install via nvm

Uses nvm to install the latest LTS release and activate it -- the recommended approach for local development.

Example · bash
# Install nvm (run once)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# Install and use LTS
nvm install --lts
nvm use --lts

Pin version with .nvmrc

A `.nvmrc` file locks the expected Node version so the whole team and CI use the same runtime.

Example · bash
# Create a .nvmrc in your project root
echo 'lts/iron' > .nvmrc

# Any developer (or CI) can then run:
nvm use

Discussion

  • Be the first to comment on this lesson.