📦 nvm/ nvm-sh
Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
Установка и запуск
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, ~/.bash_login, ~/.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.
<a id="profile_snippet"></a>
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_HOMEis present, it will place thenvmfiles there. -
You can add
--no-useto the end of the above script to postpone usingnvmuntil you manuallyuseit:
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
…
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 22.11.0 # or 24.0.0, etc
To set an alias:
nvm alias my_alias v22.11.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
To hide versions below a given version, use --min=, or set NVM_MIN to the same kind of version, for example in your shell profile; --min= overrides it. nvm install and nvm version-remote accept it too, and fail rather than select a version below it:
nvm ls-remote --min=20
nvm ls-remote --only=lts --min=v18.2
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 22.11 node --version
You can also get the path to the executable to where it was installed:
nvm which 22.11
…
Running Tests
Tests are written in [Urchin]. Install Urchin (and other dependencies) like so:
npm install
There are slow tests and fast tests. The slow tests do things like install node and check that the right versions are used. The fast tests fake this to test things like aliases and uninstalling. From the root of the nvm git repository, run the fast tests like this:
npm run test/fast
Run the slow tests like this:
npm run test/slow
Run all of the tests like this:
npm test
npm run test/fast runs make inside a clean environment (env -i ... bash -lc), so node must be on the PATH of a fresh login bash shell.
If node is only available through nvm in your current shell, it fails with "Did you forget to run npm install after cloning the repo?", even after a successful npm install.
In that case, run make directly from the root of the nvm git repository, choosing the test suite and shell:
make TEST_SUITE=fast test-zsh
Nota bene: Avoid running nvm while the tests are running.
Из README репозитория · полный README на GitHub