Node Version Manager [][3] [][4]
Table of Contents
- Intro
- About
- Installing and Updating
- Usage
- Running Tests
- Environment variables
- Bash Completion
- Compatibility Issues
- Installing nvm on Alpine Linux
- Uninstalling / Removal
- Docker For Development Environment
- Problems
- macOS Troubleshooting
- WSL Troubleshooting
- Maintainers
- Project Support
- Enterprise Support
- License
- Copyright notice
Intro
nvm
allows you to quickly install and use different versions of node via the command line.
Example:
$ nvm use 16
Now using node v16.9.1 (npm v7.21.1)
$ node -v
v16.9.1
$ nvm use 14
Now using node v14.18.0 (npm v6.14.15)
$ node -v
v14.18.0
$ nvm install 12
Now using node v12.22.6 (npm v6.14.5)
$ node -v
v12.22.6
Simple as that!
About
nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. nvm
works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.
Installing and Updating
Install & Update Script
To install or update nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
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
).
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Additional Notes
-
If the environment variable
$XDG_CONFIG_HOME
is present, it will place thenvm
files there. -
You can add
--no-use
to the end of the above script (...nvm.sh --no-use
) to postpone usingnvm
until you manuallyuse
it. -
You can customize the install source, directory, profile, and version using the
NVM_SOURCE
,NVM_DIR
,PROFILE
, andNODE_VERSION
variables. Eg:curl ... | NVM_DIR="path/to/nvm"
. Ensure that theNVM_DIR
does not contain a trailing slash. -
The installer can use
git
,curl
, orwget
to downloadnvm
, whichever is available. -
You can instruct the installer to not edit your shell config (for example if you already get completions via a zsh nvm plugin) by setting
PROFILE=/dev/null
before running theinstall.sh
script. Here's an example one-line command to do that:PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash'
Troubleshooting on Linux
On Linux, after running the install script, if you get nvm: command not found
or see no feedback from your terminal after you type command -v nvm
, simply close your current terminal, open a new terminal, and try verifying again.
Alternatively, you can run the following commands for the different shells on the command line:
bash: source ~/.bashrc
zsh: source ~/.zshrc
ksh: . ~/.profile
These should pick up the nvm
command.
Troubleshooting on macOS
Since OS X 10.9, /usr/bin/git
has been preset by Xcode command line tools, which means we can't properly detect if Git is installed or not. You need to manually install the Xcode command line tools before running the install script, otherwise, it'll fail. (see #1782)
If you get nvm: command not found
after running the install script, one of the following might be the reason:
-
Since macOS 10.15, the default shell is
zsh
and nvm will look for.zshrc
to update, none is installed by default. Create one withtouch ~/.zshrc
and run the install script again. -
If you use bash, the previous default shell, your system may not have
.bash_profile
or.bashrc
files where the command is set up. Create one of them withtouch ~/.bash_profile
ortouch ~/.bashrc
and run the install script again. Then, run. ~/.bash_profile
or. ~/.bashrc
to pick up thenvm
command. -
You have previously used
bash
, but you havezsh
installed. You need to manually add these lines to~/.zshrc
and run. ~/.zshrc
. -
You might need to restart your terminal instance or run
. ~/.nvm/nvm.sh
. Restarting your terminal/opening a new tab/window, or running the source command will load the command and the new configuration. -
If the above didn't help, you might need to restart your terminal instance. Try opening a new tab/window in your terminal and retry.
If the above doesn't fix the problem, you may try the following:
-
If you use bash, it may be that your
.bash_profile
(or~/.profile
) does not source your~/.bashrc
properly. You could fix this by addingsource ~/<your_profile_file>
to it or following the next step below. -
Try adding the snippet from the install section, that finds the correct nvm directory and loads nvm, to your usual profile (
~/.bash_profile
,~/.zshrc
,~/.profile
, or~/.bashrc
). -
For more information about this issue and possible workarounds, please refer here
Note For Macs with the Apple Silicon chip, node started offering arm64 arch Darwin packages since v16.0.0 and experimental arm64 support when compiling from source since v14.17.0. If you are facing issues installing node using nvm
, you may want to update to one of those versions or later.
Ansible
You can use a task:
- name: Install nvm
ansible.builtin.shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
Verify Installation
To verify that nvm has been installed, do:
command -v nvm
which should output nvm
if the installation was successful. Please note that which nvm
will not work, since nvm
is a sourced shell function, not an executable binary.
Note: On Linux, after running the install script, if you get nvm: command not found
or see no feedback from your terminal after you type command -v nvm
, simply close your current terminal, open a new terminal, and try verifying again.
Important Notes
If you're running a system without prepackaged binary available, which means you're going to install node or io.js from its source code, you need to make sure your system has a C++ compiler. For OS X, Xcode will work, for Debian/Ubuntu based GNU/Linux, the build-essential
and libssl-dev
packages work.
Note: nvm
also supports Windows in some cases. It should work through WSL (Windows Subsystem for Linux) depending on the version of WSL. It should also work with GitBash (MSYS) or Cygwin. Otherwise, for Windows, a few alternatives exist, which are neither supported nor developed by us:
Note: nvm
does not support [Fish] either (see #303). Alternatives exist, which are neither supported nor developed by us:
- bass allows you to use utilities written for Bash in fish shell
- fast-nvm-fish only works with version numbers (not aliases) but doesn't significantly slow your shell startup
- plugin-nvm plugin for Oh My Fish, which makes nvm and its completions available in fish shell
- fnm - fisherman-based version manager for fish
- fish-nvm - Wrapper around nvm for fish, delays sourcing nvm until it's actually used.
Note: We still have some problems with FreeBSD, because there is no official pre-built binary for FreeBSD, and building from source may need patches; see the issue ticket:
Note: On OS X, if you do not have Xcode installed and you do not wish to download the ~4.3GB file, you can install the Command Line Tools
. You can check out this blog post on how to just that:
Note: On OS X, if you have/had a "system" node installed and want to install modules globally, keep in mind that:
- When using
nvm
you do not needsudo
to globally install a module withnpm -g
, so instead of doingsudo npm install -g grunt
, do insteadnpm install -g grunt
- If you have an
~/.npmrc
file, make sure it does not contain anyprefix
settings (which is not compatible withnvm
) - You can (but should not?) keep your previous "system" node install, but
nvm
will only be available to your user account (the one used to install nvm). This might cause version mismatches, as other users will be using/usr/local/lib/node_modules/*
VS your user account using~/.nvm/versions/node/vX.X.X/lib/node_modules/*
Homebrew installation is not supported. If you have issues with homebrew-installed nvm
, please brew uninstall
it, and install it using the instructions below, before filing an issue.
Note: If you're using zsh
you can easily install nvm
as a zsh plugin. Install zsh-nvm
and run nvm upgrade
to upgrade.
Note: Git versions before v1.7 may face a problem of cloning nvm
source from GitHub via https protocol, and there is also different behavior of git before v1.6, and git prior to v1.17.10 can not clone tags, so the minimum required git version is v1.7.10. If you are interested in the problem we mentioned here, please refer to GitHub's HTTPS cloning errors article.
Git Install
If you have git
installed (requires git v1.7.10+):
- clone this repo in the root of your user profile
cd ~/
from anywhere thengit clone https://github.com/nvm-sh/nvm.git .nvm
cd ~/.nvm
and check out the latest version withgit checkout v0.40.0
- activate
nvm
by sourcing it from your shell:. ./nvm.sh
Now add these lines to your ~/.bashrc
, ~/.profile
, or ~/.zshrc
file to have it automatically sourced upon login:
(you may have to add to more than one of the above files)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm