JS
NVM
What is NVM?
Node Version Manager (NVM) is a tool that allows you to manage multiple versions of Node.js on your system. It is a command-line tool that allows you to install, manage, and switch between different versions of Node.js.
Installation
Windows
NVM is not supported on Windows. You can use fnm
instead. Open PowerShell
and run the following commands:
> fnm env --use-on-cd | Out-String | Invoke-Expression
# Download and install fnm:
> winget install Schniz.fnm
# Download and install Node.js:
> fnm install 22
# Verify the Node.js version:
> node -v # Should print "v22.14.0".
# Verify npm version:
> npm -v # Should print "10.9.2".
Node.js will be installed at %USERPROFILE%\AppData\Local\fnm_multishells
.
If you want to list all installed versions, run:
> fnm list
#or
> fnm current # return current node version
If you want to uninstall a node, run:
> fnm uninstall <version>
If you want to uninstall fnm, run:
> winget uninstall Schniz.fnm
Using WebStorm
Alternatively, you can use WebStorm to manage multiple Node.js versions. Open WebStorm and go to File > Settings > Languages & Frameworks > Node.js
. Add a Node interpreter by clicking the ...
button and selecting the Node.js version you want to use. Make sure the installation path has no spaces.
Next, open System Environment Variables
and add a new variable called NODE_HOME
with the path to the Node.js version you want to use. For example, D:\node\22.14.0
. Then, add %NODE_HOME%
to the Path
variable.
Linux & macOS
Automatic Installation
1.1 Running either of the above commands downloads a script and runs it. The script clones the nvm repository to ~/.nvm, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
Manual Installation
2.1 If you’re having trouble downloading from GitHub, you can download it to your local machine first.
$ curl -o install_nvm.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh
2.2 Then use scp
to copy it to your server. For example:
$ scp install_nvm.sh ubuntu@server_ip:/home/ubuntu/
# replace ubuntu with your username and server_ip with your server IP address
2.3 Then run the script on your server.
$ bash install_nvm.sh
2.4 The script will add the following lines to your shell profile file (.bashrc
, .bash_profile
, .zshrc
, or .profile
).
export NVM_DIR="$HOME/.nvm" # Set the NVM directory:
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Verify Installation
Log out and log back in, or restart your terminal, and run the following command to verify that nvm is installed:
$ nvm -v
Install Node.js
List Available Node.js Versions
$ nvm ls-remote
Choose a Node.js Version:
$ nvm install node # Install the latest version
#or
$ nvm install 18 # Install Node.js v18
#or
$ nvm install --lts # Install the latest LTS version
Use a Specifc Node.js Version
$ nvm use 18
List Node.js Installed
$ nvm ls
Uninstall
Uninstall a Specific Node.js Version
$ nvm uninstall <version>
If the current version is in use, you can switch to another version before uninstalling:
$ nvm use <version>
#or
$ nvm deactivate
Then uninstall the version:
$ nvm uninstall <version>
Check the current version:
$ nvm current
Uninstall NVM
$ rm -rf ~/.nvm
Remove the nvm entry from shell configuation file:
Zsh (default shell on newer macOS)
$ nano ~/.zshrc
Look for and remove lines like:
$ export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"