Setting up Node.js with installers, nvm, and LTS

Install Node.js, switch versions between projects, and verify the runtime your terminal uses.

🎯 Introduction

By the end of this article, you will be able to install Node.js, switch versions between projects, and verify the runtime your terminal uses.


🧱 Choose a supported version

LTS stands for long-term support. These releases receive maintenance during their support period and suit learning and projects that need stability. Current releases offer the latest features; EOL means end of life. Check the official release status rather than choosing solely by version number.

This course pins Node.js 24.19.0 to make the examples reproducible. Real projects should adopt security updates on supported release lines after checking compatibility. A pinned tutorial version is no reason to stop updating indefinitely.


🛠 Install and verify

If you only need one version, choose your operating system on the Node.js download page. Windows offers an .msi installer and macOS a .pkg installer; open it and follow the steps. On Linux, or when you need multiple versions, you can use nvm as described below. Reopen your terminal after installation.

First run node -v. With the course version installed, it prints v24.19.0, confirming that the terminal can find and run Node.js. If the command is not found, reopen the terminal, then check that installation completed.

Next run npm -v. It prints the installed npm version, such as 11.11.0; your result may differ. npm is a package manager used to install third-party code for projects. It is a separate tool from Node.js, so their version numbers do not need to match.

The Node.js download page and installers change over time, including button labels and locations. Use these steps as a guide and follow the current official page.

🧰 Manage multiple versions with nvm

nvm is a Node.js version manager. It lets different projects use different versions without repeatedly uninstalling them. For macOS, Linux, and WSL on Windows, follow the official nvm installation instructions. WSL lets you run a Linux environment on Windows.

For native Windows terminals, use nvm-windows. It is a separate project with its own installation and configuration instructions; do not reuse the nvm installation script for it.

Installation instructions and interfaces for these projects may change. The commands below use nvm on macOS/Linux. Install the tool for your platform before running them.

macOS/Linux: install the version manager

The following uses nvm 0.40.3. Following its official installation instructions, run:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

curl downloads the installation script for that version, and bash after the pipe executes it. The script installs nvm for the current user and configures shell loading. Close and reopen your terminal, then run nvm --version. If it prints 0.40.3, the tool is ready.

If nvm is not found, use the installation output to check that your shell configuration loads nvm, then reopen the terminal. Resolve this before continuing with Node.js version switching.

Install and select a Node.js version

First download the version used in this course:

nvm install 24.19.0

After installation, the tool reports that the version is available. Installing it locally does not require removing versions used by other projects.

Switch versions in the terminal where you need it:

nvm use 24.19.0

On success, nvm reports that it is using v24.19.0. Run node -v to verify that it prints v24.19.0. Check the active version again when opening another terminal.

Record the project version in .nvmrc

For projects using nvm on macOS/Linux, create a .nvmrc file in the project root containing just 24.19.0 on one line. From that directory, run nvm use without a version number to read the file and switch versions.

If that version is not installed, run nvm install in the directory first. .nvmrc records a version; merely having the file does not switch your terminal environment automatically.

If the version is still wrong after switching, reopen the terminal and run command -v node on macOS/Linux or where.exe node on Windows to locate the command. Multiple installation sources can cause it to resolve to another version.


❓ Questions and answers

Q1: Do I need to install npm separately after Node.js?

Common official installation methods include npm. Run npm -v to check first.

Q2: Can teammates switch versions automatically with just .nvmrc?

They need a compatible version manager and must run the switching command or configure automatic switching.

Q3: Do all systems use the same nvm?

No. nvm-windows and nvm-sh/nvm are different tools.


🧪 Exercise

Switch to the course version and create version.mjs. Print the version with console.log(process.version) and compare it with node -v. process.version reports the Node.js version actually running the file.

// Write your code here

🎉 Try these techniques with your own examples!