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 |
# 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 |
# 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.
Run the downloaded installer and follow the 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.
12node -v # v24.19.0 npm -v # 11.17.0
# Windows
Download the Windows Installer (.msi) for the LTS version.
Run the downloaded installer and follow the setup wizard.
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.
12node -v # v24.19.0 npm -v # 11.17.0
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.
1Set-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.
1curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.7/install.sh | bash
If you use Homebrew, you can install NVM with the following command.
1brew install nvm
When the install script finishes, the following NVM initialization code is automatically added to your shell configuration file (~/.zshrc, ~/.bashrc, and so on).
123export 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.
123vim ~/.zshrc # or vim ~/.bashrc
Once you're in the Vim editor, you can check or edit the content with the following commands.
1234567# 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.
1nvm -v # 0.40.7
Now let's install Node.js with NVM.
12nvm 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.
12node -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.
Go to the NVM-Windows Releases page and download the latest nvm-setup.exe.
Run the downloaded installer with administrator rights and follow the setup wizard.
You can choose any installation path, but we recommend keeping the default.
When the installation is complete, open a new terminal (CMD, PowerShell) to check it.
1nvm version # 1.2.2
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.
12nvm 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.
12node -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.
1Set-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.
1234sudo 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.
1rm -rf ~/.nvm
Then find and remove the following NVM initialization code from your shell configuration file (~/.zshrc, ~/.bashrc, and so on).
123export 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.
123nvm -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\nodejsC:\Users\{username}\AppData\Roaming\npmC:\Users\{username}\AppData\Roaming\npm-cacheC:\Users\{username}\.npmrcC:\Users\{username}\AppData\Roaming\nvmC:\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_PATHNVM_HOME(NVM-Windows)NVM_SYMLINK(NVM-Windows)
- In the
Pathvariable, 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.
12345nvm -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.
124
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.
12nvm 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 |
Thanks for reading to the end.
Likes and kind comments help keep this blog going!