How to Install Node.js with nvm

Install nvm on Mac or Linux, use it to install the current Node.js LTS release, verify the version, and set a default so every new terminal uses it.

nvm (Node Version Manager) installs Node.js per user and lets you switch between versions with one command. Installing Node this way avoids the permission problems that come with system-wide installs.

Run the nvm install script

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

The script clones nvm into ~/.nvm and adds a few lines to your shell profile (~/.zshrc, ~/.bashrc, or ~/.bash_profile) so the nvm command loads in new shells.

Reload the shell

Close the terminal and open a new one, or source the profile the script edited:

source ~/.zshrc

Use source ~/.bashrc if bash is your shell. Confirm nvm loaded:

nvm --version
0.40.3

Install the LTS release of Node.js

nvm install --lts

This downloads the current long-term support version (Node 22 at the time of writing) along with the matching npm.

Switch to it

nvm use --lts

Then check that Node responds:

node -v

The output starts with v22. Run npm -v to confirm npm came along with it.

Set the default version

nvm use only applies to the current terminal. To make Node 22 load automatically in every new shell:

nvm alias default 22

Open a new terminal and run node -v again to confirm the default took effect.

On Windows. The nvm install script does not run on Windows. Use nvm-windows, a separate project with its own installer, or fnm, which works on Mac, Linux, and Windows and supports the same install and use workflow.

To install a specific version. nvm install 20 installs the latest 20.x release, nvm use 20 switches to it, and nvm ls lists everything installed on the machine.

More Coding how-tos