# nvm — Manage Node.js Versions

> Practical guide to nvm: install, switch and pin multiple Node.js versions per shell and project with .nvmrc.

Source: https://www.jpkc.com/db/en/cheatsheets/package-managers/nvm/

<!-- PROSE:intro -->
nvm (Node Version Manager) keeps any number of Node.js versions installed side by side and lets you switch between them per shell or per project. Instead of overwriting one globally installed Node version, you can keep Node 18 for a legacy project and Node 22 for a new one ready at the same time. With a `.nvmrc` file you pin the right version straight into the project, so everyone on the team automatically uses the same Node. One thing to keep in mind: nvm is not a binary but a shell function loaded at startup from your `.bashrc` or `.zshrc` – which is why `nvm use` only ever affects the current shell.
<!-- PROSE:intro:end -->

## Install & List Versions

`nvm install <version>` — Install a specific Node.js version.

```bash
nvm install 20
```

`nvm install --lts` — Install the latest LTS (Long-Term Support) version.

```bash
nvm install --lts
```

`nvm install node` — Install the latest current version.

```bash
nvm install node
```

`nvm ls` — List all locally installed versions.

```bash
nvm ls
```

`nvm ls-remote` — List all available versions for installation.

```bash
nvm ls-remote
```

`nvm ls-remote --lts` — List only LTS versions available.

```bash
nvm ls-remote --lts
```

`nvm uninstall <version>` — Uninstall a specific Node.js version.

```bash
nvm uninstall 18
```

## Switch Versions

`nvm use <version>` — Switch to a specific installed version.

```bash
nvm use 20
```

`nvm use --lts` — Switch to the latest installed LTS version.

```bash
nvm use --lts
```

`nvm use node` — Switch to the latest installed version.

```bash
nvm use node
```

`nvm use system` — Switch to the system-installed Node.js.

```bash
nvm use system
```

`nvm current` — Show the currently active Node.js version.

```bash
nvm current
```

## Aliases & Defaults

`nvm alias default <version>` — Set the default version for new shells.

```bash
nvm alias default 20
```

`nvm alias default lts/*` — Set the default to the latest LTS.

```bash
nvm alias default lts/*
```

`nvm alias <name> <version>` — Create a custom alias for a version.

```bash
nvm alias project-a 18.19.0
```

`nvm unalias <name>` — Remove a custom alias.

```bash
nvm unalias project-a
```

## .nvmrc & Auto-Switch

`echo '<version>' > .nvmrc` — Create a .nvmrc file to pin the Node version for a project.

```bash
echo '20' > .nvmrc
```

`nvm use` — Read .nvmrc and switch to that version (auto-detect).

```bash
nvm use
```

`nvm install` — Install the version specified in .nvmrc if not present.

```bash
nvm install
```

## Utilities

`nvm which <version>` — Show the path to a Node.js version binary.

```bash
nvm which 20
```

`nvm exec <version> <command>` — Run a command with a specific Node version.

```bash
nvm exec 18 node -v
```

`nvm run <version> <script>` — Run a script with a specific Node version.

```bash
nvm run 20 app.js
```

`nvm reinstall-packages <version>` — Reinstall global npm packages from another version.

```bash
nvm reinstall-packages 18
```

`nvm cache clear` — Clear the nvm download cache.

```bash
nvm cache clear
```

`nvm --version` — Show the installed nvm version.

```bash
nvm --version
```

<!-- PROSE:outro -->
## Conclusion

nvm takes the pain out of juggling Node.js versions by hand: you install them side by side, pin a `.nvmrc` per project and switch with a single `nvm use`. Keep in mind that each Node version has its **own** set of globally installed packages – after switching versions your global CLIs will be missing at first, and `nvm reinstall-packages` helps carry them over. The official installation runs through a `curl … | bash` script: as a rule you shouldn't run such pipe-to-shell commands blindly, but review the script first or pin it. Because nvm is a shell function rather than a binary, it only works in shells where it has been sourced from `.bashrc`/`.zshrc` – in cron jobs or CI it won't be available without explicit sourcing.

## Further Reading

- [nvm – GitHub project](https://github.com/nvm-sh/nvm) – source code, installation and full documentation
- [Node.js – Releases & versions](https://nodejs.org/en/about/previous-releases) – LTS schedule and supported Node versions
<!-- PROSE:outro:end -->

## Related Commands

- [apk](https://www.jpkc.com/db/en/cheatsheets/package-managers/apk/) – Alpine Linux package manager
- [apt](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt/) – convenient package front-end for Debian/Ubuntu
- [apt-get](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt-get/) – classic package tool for Debian/Ubuntu

