nvm-sh/nvm

▲ 46 stars today★ 95,913⑂ 10,753

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions.

About nvm-sh/nvm

nvm-sh/nvm is an open-source project on GitHub, mainly written in Shell. Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions. It currently holds 95,913 stars and 10,753 forks with 372 open issues, and was last pushed on 2026-11-12 (repository created 2010-04-15).

Project Overview

Git Homed tracks it on the Today's Trending board, currently at rank #93 with 46 new stars today.

GitHub Repository Details

Repository nvm-sh/nvm · default branch master · size 4917 KB · watchers 1,148 · source: GitHub REST API and repository README

README

https://github.com/nvm-sh/nvm/blob/HEAD/nvm project logo

Node Version Manager [Tests][3] [nvm version][4] CII Best Practices

Table of Contents

Intro

nvm allows you to quickly install and use different versions of node via the command line.

Example:

$ nvm install 24
Now using node v24.14.0 (npm v11.9.0)
$ node -v
v24.14.0
$ nvm use 22
Now using node v22.22.1 (npm v10.9.4)
$ node -v
v22.22.1
$ nvm use 20
Now using node v20.20.1 (npm v10.8.2)
$ node -v
v20.20.1

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.41.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.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 (~/.bashrc, ~/.bash_profile, ~/.zshrc, or ~/.profile). If you find the install script is updating the wrong profile file, set the $PROFILE env var to the profile file’s path, and then rerun the installation script.

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

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" --no-use # This loads nvm, without auto-using the default version
Eg: curl ... | NVM_DIR="path/to/nvm". Ensure that the NVM_DIR does not contain a trailing slash.

Installing in Docker

When invoking bash as a non-interactive shell, like in a Docker container, none of the regular profile files are sourced. In order to use nvm, node, and npm like normal, you can instead specify the special BASH_ENV variable, which bash sources when invoked non-interactively.

# Use bash for the shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

Create a script file sourced by both interactive and non-interactive bash shells

ENV BASH_ENV="${HOME:-/root}/.bash_env" RUN touch "${BASH_ENV}" RUN echo '. "${BASH_ENV}"' >> ~/.bashrc

Download and install nvm

RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh | PROFILE="${BASH_ENV}" bash RUN echo node > .nvmrc RUN nvm install
Installing in Docker for CICD-Jobs

More robust, works in CI/CD-Jobs. Can be run in interactive and non-interactive containers. See https://github.com/nvm-sh/nvm/issues/3531.

FROM ubuntu:latest
ARG NODE_VERSION=20

install curl

RUN apt update && apt install curl -y

install nvm

RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh | bash

set env

ENV NVM_DIR="${HOME:-/root}/.nvm"

install node

RUN bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION"

set ENTRYPOINT for reloading nvm-environment

ENTRYPOINT ["bash", "-c", "source $NVM_DIR/nvm.sh && exec \"$@\"", "--"]

set cmd to bash

CMD ["/bin/bash"]

This example defaults to installation of nodejs version 20.x.y. Optionally you can easily override the version with docker build args like:

docker build -t nvmimage --build-arg NODE_VERSION=19 .

After creation of the image you can start container interactively and run commands, for example:

docker run --rm -it nvmimage

root@0a6b5a237c14:/# nvm -v 0.41.0

root@0a6b5a237c14:/# node -v v19.9.0

root@0a6b5a237c14:/# npm -v 9.6.3

Noninteractive example:

user@host:/tmp/test $ docker run --rm -it nvmimage node -v
v19.9.0
user@host:/tmp/test $ docker run --rm -it nvmimage npm -v
9.6.3

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:

If the above doesn't fix the problem, you may try the following: 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.41.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 Git Bash (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: 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: 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 (you can set NVM_AUTO_USE=true to have it automatically detect and use .nvmrc files).

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+):

1. clone this repo in the root of your user profile

1. cd ~/.nvm and check out the latest version with git checkout v0.41.0 1. 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 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:

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)

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+):

1. change to the $NVM_DIR 1. pull down the latest changes 1. check out the latest version 1. activate the new version

(
  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:

nvm install node # "node" is an alias for the latest version

To install a specific version of node:

nvm install 14.7.0 # or 16.3.0, 12.22.1, etc

To set an alias:

nvm alias my_alias v14.4.0
Make sure that your alias does not contain any spaces or slashes.

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:

nvm ls-remote

When no version or --lts filter is given, the list also marks the version the node alias would install, and every version that one of your own aliases would resolve to. Each kind of annotation always starts in the same column, so the output can be sliced with cut -c or similar tools:

        v20.9.0   (Latest LTS: Iron)                        (Aliases: work)
        v21.0.0
        v21.1.0
        v21.2.0                            (Latest: node)   (Aliases: default)

And then in any new shell just use the installed version:

nvm use node

Or you can just run it:

nvm run node --version

Or, you can run any arbitrary command in a subshell with the desired version of node:

nvm exec 4.2 node --version

You can also get the path to the executable to where it was installed:

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:

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:

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 version of node and migrate your existing installed packages, use:

nvm install --reinstall-packages-from=current 'lts/*'

Version Categories

Every version of node belongs to exactly one of these categories:

By default, nvm selects versions from every category except alpha, so nvm install node, nvm install 27, and nvm ls-remote never pick or show an Alpha. Every command that selects or lists versions accepts --only= with a comma

GitHub Stars & Activity

95,913Stars
10,753Forks
372Open issues
ShellLanguage

GitHub Popularity

GitHub stars95,913
Forks10,753
Open issues372
Primary languageShell
LicenseMIT
Stars gained today46
Created2010-04-15
Last pushed2026-11-12

Trending History

Daily boardrank #93 · ▲ 46 stars
Weekly boardrank #93 · ▲ 427 stars

Related GitHub Projects

1

mattpocock / skills

Shell★ 326,317⑂ 27,407▲ 793 stars
→
2

obra / superpowers

Shell★ 318,900⑂ 28,421▲ 1,905 stars
→
3

ohmyzsh / ohmyzsh

Shell★ 190,647⑂ 27,279▲ 59 stars
→
4

msitarzewski / agency-agents

Shell★ 168,916⑂ 27,436▲ 275 stars
→
5

mack-a / v2ray-agent

Shell★ 22,430⑂ 5,565▲ 44 stars
→
6

affaan-m / ECC

JavaScript★ 304,931⑂ 44,904▲ 718 stars
→
7

ossu / computer-science

HTML★ 211,199⑂ 26,151▲ 66 stars
→
8

DietrichGebert / ponytail

JavaScript★ 192,507⑂ 10,798▲ 785 stars
→

More Trending Repositories