99

Concurrent visitors over the last 30 minutes. (~)

Peak concurrent visitors -
Yesterday: 0 / Today: 0

Node.js (NPM) Installation and NVM Version Management Guide

Node.js (NPM) Installation and NVM Version Management Guide

# Overview

Node.js is a JavaScript runtime environment built on Chrome's V8 JavaScript engine.
It lets you run JavaScript outside the browser, and you need it not only for server development but also to use front-end development tools.

When you install Node.js, NPM (Node Package Manager) is installed along with it.
NPM is a tool for installing and managing JavaScript packages (libraries), and it's an essential part of modern web development.

Node.js offers two kinds of versions: LTS and Current.
Unless you have a specific reason, we recommend installing the LTS version.

Type Description Recommended for
LTS (Long Term Support) Long-term support version, stable Most users, production projects
Current Includes the latest features, relatively unstable When you want to test the latest features

LTS stands for Long Term Support, and even-numbered versions (20, 22, 24, and so on) are designated as LTS.
LTS versions get security updates and bug fixes for about 30 months, so they're a good fit for production projects where stability matters.
Current versions are odd-numbered (19, 21, 23, and so on), and they include the latest features but may be less stable.

# Installing Node.js

There are two main ways to install Node.js: using the official installer, or using a version management tool such as NVM (or NVM-Windows).
Here is how the methods compare.

Method Pros Cons Recommended for
Official installer Easy to install No version management Beginners who don't need version management
NVM (macOS/Linux) Manages multiple versions, avoids permission issues No Windows support Developers on macOS/Linux
NVM-Windows Manages multiple versions on Windows Requires administrator rights Developers on Windows

In general, we recommend using NVM (Node Version Manager).
With NVM, you can install and switch between multiple versions of Node.js, and use a different Node.js version for each project.

# Official installer

Let's look at how to install Node.js with the official installer.
Simply download the installer and run through the installation.

If you need to manage Node.js versions, use NVM or NVM-Windows!

# macOS

Download the macOS Installer (.pkg) for the LTS version.

Downloading the macOS Installer

Run the downloaded installer and follow the setup wizard.

Setup wizard

When the installation is complete, check it with the following commands in the terminal.
A terminal that was already open before the installation may not pick up the change, so open a new terminal to check.

BASH
1
2
node -v # v24.19.0 npm -v # 11.17.0

# Windows

Download the Windows Installer (.msi) for the LTS version.

Downloading the Windows Installer

Run the downloaded installer and follow the setup wizard.

On Windows, we recommend running the installer with administrator rights.
If you install without administrator rights, the installation may fail because you don't have write permission for the Program Files path, or you may get permission errors later when installing global packages (npm install -g).
Right-click the installer and select 'Run as administrator'.

When the installation is complete, check it with the following commands in the terminal (CMD, PowerShell).
A terminal that was already open before the installation may not pick up the change, so open a new terminal to check.

BASH
1
2
node -v # v24.19.0 npm -v # 11.17.0

In PowerShell, node -v may work fine while npm -v alone fails with the error "npm.ps1 cannot be loaded because running scripts is disabled on this system."
node is an executable, but npm runs as a PowerShell script (npm.ps1), so it can be blocked by the execution policy that prevents scripts from running.
This doesn't happen in CMD.

In that case, change the execution policy for the current user with the command below in PowerShell, then run npm -v again.
RemoteSigned is a policy that runs local scripts you wrote yourself as they are, but only runs scripts downloaded from the internet if they are signed.

POWERSHELL
1
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser # Enter Y when prompted to confirm

# NVM (macOS)

NVM (Node Version Manager) is a tool that lets you install and switch between multiple versions of Node.js on macOS and Linux.
It's very useful when you change versions often or need different Node.js versions for different projects.

Copy the following command, paste it into the terminal, and run it to install NVM.

BASH
1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.7/install.sh | bash
Install NVM (cURL)

If you use Homebrew, you can install NVM with the following command.

BASH
1
brew install nvm
Install NVM with Homebrew

When the install script finishes, the following NVM initialization code is automatically added to your shell configuration file (~/.zshrc, ~/.bashrc, and so on).

~/.zshrc
BASH
1
2
3
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Open the configuration with the following command to check it.
If the code isn't there, you need to add it yourself.

BASH
1
2
3
vim ~/.zshrc # or vim ~/.bashrc

Once you're in the Vim editor, you can check or edit the content with the following commands.

BASH
1
2
3
4
5
6
7
# Check the content :q ENTER # Quit without saving # Edit the content i # Insert mode ESC # Command mode :wq ENTER # Save and quit

Then check that NVM was installed correctly.

BASH
1
nvm -v # 0.40.7

Now let's install Node.js with NVM.

BASH
1
2
nvm install 24 # Install version 24 nvm use 24 # Use version 24

When the installation is complete, check it with the following commands in the terminal.
A terminal that was already open before the installation may not pick up the change, so open a new terminal to check.

BASH
1
2
node -v # v24.19.0 npm -v # 11.17.0

# NVM-Windows

On Windows, use NVM-Windows instead of NVM.
NVM-Windows is a separate project from the original NVM (macOS/Linux), but you can manage Node.js versions with similar commands.

Before installing NVM-Windows, if Node.js is already installed, you must remove it first.
Otherwise, it may conflict with the existing Node.js.

Go to the NVM-Windows Releases page and download the latest nvm-setup.exe.

Downloading the installer

Run the downloaded installer with administrator rights and follow the setup wizard.
You can choose any installation path, but we recommend keeping the default.

Setup wizard

When the installation is complete, open a new terminal (CMD, PowerShell) to check it.

BASH
1
nvm version # 1.2.2
Check the NVM-Windows version

A terminal that was already open before the installation may not pick up the change, so open a new terminal to check.
After installing a version, you need to set it as the one to use.

If the nvm use command doesn't work, open the terminal with 'Run as administrator' and enter the command again.

BASH
1
2
nvm install 24 # Install version 24 nvm use 24.19.0 # Use version 24

When the installation is complete, check it with the following commands in the terminal.
A terminal that was already open before the installation may not pick up the change, so open a new terminal to check.

BASH
1
2
node -v # v24.19.0 npm -v # 11.17.0

If only npm -v fails in PowerShell with an error saying the npm.ps1 file cannot be loaded, change the execution policy with the following command and run it again.

POWERSHELL
1
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser # Enter Y when prompted to confirm

# Uninstalling Node.js

# macOS

If you installed Node.js with the official installer, run the following commands in the terminal to remove it.

BASH
1
2
3
4
sudo rm -rf /usr/local/lib/node_modules sudo rm -rf /usr/local/include/node sudo rm /usr/local/bin/node sudo rm /usr/local/bin/npm

If you installed it with NVM, deleting the ~/.nvm folder removes NVM along with all installed Node.js versions.

BASH
1
rm -rf ~/.nvm

Then find and remove the following NVM initialization code from your shell configuration file (~/.zshrc, ~/.bashrc, and so on).

~/.zshrc
BASH
1
2
3
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

After the change, open a new terminal and check that the commands no longer work.

BASH
1
2
3
nvm -v # command not found: nvm node -v # command not found: node npm -v # command not found: npm

# Windows

Find the Node.js entry in Settings (Control Panel) > Apps > Apps & features and uninstall it.

Then check the following Node.js-related cache paths and delete them.
If you used NVM-Windows, check and delete its paths too.

  • C:\Program Files\nodejs
  • C:\Users\{username}\AppData\Roaming\npm
  • C:\Users\{username}\AppData\Roaming\npm-cache
  • C:\Users\{username}\.npmrc
  • C:\Users\{username}\AppData\Roaming\nvm
  • C:\Users\{username}\.nvm

Finally, clean up the environment variables.
Press Win + R, type sysdm.cpl and run it, then click Environment Variables on the Advanced tab.

  • In System variables, delete the following variables if they exist.
    • NODE_PATH
    • NVM_HOME (NVM-Windows)
    • NVM_SYMLINK (NVM-Windows)
  • In the Path variable, find and remove the following paths.
    • C:\Program Files\nodejs
    • %NVM_HOME% (NVM-Windows, default: C:\Users\{username}\AppData\Roaming\nvm)
    • %NVM_SYMLINK% (NVM-Windows, default: C:\nvm4w\nodejs)

After the change, open a new terminal and check that the commands no longer work.

BASH
1
2
3
4
5
nvm -v node -v npm -v # 'xxx' is not recognized as an internal or external command, operable program or batch file. # The term 'xxx' is not recognized as the name of a cmdlet, function, script file, or operable program.

# NVM commands

Task NVM (macOS) NVM-Windows
Install LTS nvm install --lts nvm install lts
Install the latest version nvm install node nvm install latest
Install a specific version nvm install 24 nvm install 24
Switch versions nvm use 24 nvm use 24.19.0
Check the current version nvm current nvm current
List installed versions nvm ls nvm list
List remote versions nvm ls-remote nvm list available
Set the default version nvm alias default 24 -
Remove a specific version nvm uninstall 24 nvm uninstall 24.19.0
Disable NVM nvm deactivate nvm off
Enable NVM - nvm on
Check the NVM version nvm -v(nvm --version) nvm version

# .nvmrc

If you create a .nvmrc file in the project root, you can specify the Node.js version to use in that project.
This is useful for keeping the Node.js version the same across your team or managing different versions per project.

.nvmrc is supported only by NVM (macOS/Linux).
NVM-Windows doesn't support the .nvmrc file.

.nvmrc
TEXT
1
24

If you run nvm use or nvm install without a version in a directory that has a .nvmrc file, the version specified in the file is applied automatically.

BASH
1
2
nvm use # Switch to the version specified in .nvmrc nvm install # Install the version specified in .nvmrc

You can specify the version in a .nvmrc file in several formats.

Format Description Example
Major version The latest version of that major 24
Exact version A specific version 24.19.0
lts/* The latest LTS version lts/*
lts/name A specific LTS line lts/krypton
node The latest version node