Skip to content
FLAVIO COPES
flaviocopes.com

How to install Node.js

By

Learn how to install Node.js with a version manager or the official installer, choose an LTS release, verify Node and npm, and switch project versions.

~~~

The best way to install Node.js for development is usually a version manager. It lets you install more than one Node release and switch between them for different projects.

If you only need one version, you can use an installer from the official Node.js download page.

For most production work, choose an active Long Term Support release rather than the Current release. The exact supported releases change over time, so check the Node.js release schedule.

Install Node.js with nvm

nvm is a popular version manager for macOS, Linux, and Windows Subsystem for Linux. It does not support native Windows shells.

Use the install command published in the official nvm repository. The command includes the current nvm release, so copy it from the repository instead of relying on an old version in a tutorial.

After installing nvm, open a new terminal and install the latest LTS release:

nvm install --lts
nvm use --lts

The first version installed becomes the default in new shells. You can also set it explicitly:

nvm alias default 'lts/*'

List the Node versions installed on your machine:

nvm ls

List releases available to install:

nvm ls-remote --lts

Pin the Node version for a project

Create an .nvmrc file in the project root:

lts/*

Then run:

nvm install
nvm use

A team can put a specific supported release line in .nvmrc when it needs reproducible local and CI environments. Update that file as part of normal dependency maintenance.

Use the official installer

The Node.js download page provides installers and prebuilt binaries.

This is simple, but switching between Node releases later is less convenient than with a version manager. Avoid installing Node from an unofficial download site.

Verify the installation

Node includes npm. Check both commands:

node --version
npm --version

You can now run a JavaScript file:

node app.js

If your shell says node: command not found, restart the terminal and check the setup instructions printed by your installer or version manager. Do not use sudo to work around npm permission errors; fix the Node installation or use a per-user version manager instead.

Tagged: Node.js ยท All topics
~~~

Related posts about node: