Node Version Manager
Table of Contents
Intro
About
Installing and Updating
Install & Update Script
Additional Notes
Troubleshooting on Linux
Troubleshooting on macOS
Ansible
Verify Installation
Important Notes
Git Install
Manual Install
Manual Upgrade
Usage
Long-term Support
Migrating Global Packages While Installing
Default Global Packages From File While Installing
io.js
System Version of Node
Listing Versions
Setting Custom Colors
Persisting custom colors
Suppressing colorized output
Restoring PATH
Set default node version
Use a mirror of node binaries
.nvmrc
Deeper Shell Integration
bash
Automatically call nvm use
zsh
Calling nvm use automatically in a directory with a .nvmrc file
fish
Calling nvm use automatically in a directory with a .nvmrc file
Running Tests
Environment variables
Bash Completion
Usage
Compatibility Issues
Installing nvm on Alpine Linux
Alpine Linux 3.13+
Alpine Linux 3.5 - 3.12
Uninstalling / Removal
Manual Uninstall
Docker For Development Environment
Problems
macOS Troubleshooting
WSL Troubleshooting
Maintainers
License
Copyright notice
Intro
nvm allows you to quickly install and use different versions of node via the command line.
Example:
- ``` shell
- $ 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 installor updatenvm, you should run the install script. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
- ``` shell
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
- ```
- ``` shell
- wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/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` ).
- ``` shell
- 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 the nvm files there.
You can add --no-use to the end of the above script (...nvm.sh --no-use ) to postpone using nvm until you manually use it.
You can customize the install source, directory, profile, and version using the NVM_SOURCE, NVM_DIR, PROFILE, and NODE_VERSION variables. Eg: curl ... | NVM_DIR="path/to/nvm". Ensure that the NVM_DIR does not contain a trailing slash.
The installer can use git, curl, or wget to download nvm, whichever is available.
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 with touch ~/.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 with `touch /.bash_profile or touch /.bashrc and run the install script again. Then, run . /.bash_profile or . /.bashrc to pick up the nvm` command.
You have previously used bash, but you have zsh 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 adding source ~/<your_profile_file>` to it or follow 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
NoteFor Macs with the M1 chip, node started offering arm64arch darwin packages since v16.0.0 and experimental arm64support 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:
- ``` yaml
- - name: Install nvm
- ansible.builtin.shell: >
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
- args:
- creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
- ```
Verify Installation
To verify that nvm has been installed, do:
- ``` shell
- 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 nodejs 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 support 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:
nvm-windows
nodist
nvs
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:
[#900] [Bug] nodejs on FreeBSD may need to be patched
nodejs/node#3716
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:
How to Install Command Line Tools in OS X Mavericks & Yosemite (Without Xcode)
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 need sudo to globally install a module with npm -g, so instead of doing sudo npm install -g grunt, do instead npm install -g grunt
If you have an ~/.npmrc file, make sure it does not contain any prefix settings (which is not compatible with nvm )
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 then git clone https://github.com/nvm-sh/nvm.git .nvm
cd ~/.nvm and check out the latest version with git checkout v0.39.3
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)
- ``` shell
- 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 bash_completion
- ```
Manual Install
For a fully manual install, execute the following lines to first clone the nvm repository into $HOME/.nvm, and then load nvm :
- ``` shell
- export NVM_DIR="$HOME/.nvm" && (
- git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
- cd "$NVM_DIR"
- git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
- ) && \. "$NVM_DIR/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)
- ``` shell
- 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 bash_completion
- ```
Manual Upgrade
For manual upgrade with git (requires git v1.7.10+):
change to the $NVM_DIR
pull down the latest changes
check out the latest version
activate the new version
- ``` shell
- (
- cd "$NVM_DIR"
- git fetch --tags origin
- git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
- ) && \. "$NVM_DIR/nvm.sh"
- ```
Usage
To download, compile, and install the latest release of node, do this:
- ``` shell
- nvm install node # "node" is an alias for the latest version
- ```
To install a specific version of node:
- ``` shell
- nvm install 14.7.0 # or 16.3.0, 12.22.1, etc
- ```
The first version installed becomes the default. New shells will start with the default version of node (e.g., nvm alias default ).
You can list available versions using ls-remote :
- ``` shell
- nvm ls-remote
- ```
And then in any new shell just use the installed version:
- ``` shell
- nvm use node
- ```
Or you can just run it:
- ``` shell
- nvm run node --version
- ```
Or, you can run any arbitrary command in a subshell with the desired version of node:
- ``` shell
- nvm exec 4.2 node --version
- ```
You can also get the path to the executable to where it was installed:
- ``` shell
- nvm which 12.22
- ```
In place of a version pointer like "14.7" or "16.3" or "12.22.1", you can use the following special default aliases with nvm install, nvm use, nvm run, nvm exec, nvm which, etc:
node : this installs the latest version of node
iojs : this installs the latest version of io.js
stable : this alias is deprecated, and only truly applies to node v0.12 and earlier. Currently, this is an alias for node.
unstable : this alias points to node v0.11 - the last "unstable" node release, since post-1.0, all node versions are stable. (in SemVer, versions communicate breakage, not stability).
Long-term Support
Node has a schedule for long-term support (LTS) You can reference LTS versions in aliases and .nvmrc files with the notation lts/* for the latest LTS, and lts/argon for LTS releases from the "argon" line, for example. In addition, the following commands support LTS arguments:
nvm install --lts / nvm install --lts=argon / nvm install 'lts/*' / nvm install lts/argon
nvm uninstall --lts / nvm uninstall --lts=argon / nvm uninstall 'lts/*' / nvm uninstall lts/argon
nvm use --lts / nvm use --lts=argon / nvm use 'lts/*' / nvm use lts/argon
nvm exec --lts / nvm exec --lts=argon / nvm exec 'lts/*' / nvm exec lts/argon
nvm run --lts / nvm run --lts=argon / nvm run 'lts/*' / nvm run lts/argon
nvm ls-remote --lts / nvm ls-remote --lts=argon nvm ls-remote 'lts/*' / nvm ls-remote lts/argon
nvm version-remote --lts / nvm version-remote --lts=argon / nvm version-remote 'lts/*' / nvm version-remote lts/argon
Any time your local copy of nvm connects to https://nodejs.org, it will re-create the appropriate local aliases for all available LTS lines. These aliases (stored under $NVM_DIR/alias/lts ), are managed by nvm, and you should not modify, remove, or create these files - expect your changes to be undone, and expect meddling with these files to cause bugs that will likely not be supported.
To get the latest LTS ve