All Snippets
Install NVM and Manage Node.js Versions
Install Node Version Manager and switch between Node.js versions per project.
NVM (Node Version Manager) lets you install and switch between multiple Node.js versions. Essential when working across projects that target different Node versions.
Install NVMbash
| 1 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash |
| 2 | |
| 3 | # Reload your shell |
| 4 | source ~/.bashrc # or ~/.zshrc |
Common commandsbash
| 1 | # Install latest LTS |
| 2 | nvm install --lts |
| 3 | |
| 4 | # Install a specific version |
| 5 | nvm install 22 |
| 6 | |
| 7 | # List installed versions |
| 8 | nvm ls |
| 9 | |
| 10 | # Switch version |
| 11 | nvm use 22 |
| 12 | |
| 13 | # Set default version |
| 14 | nvm alias default 22 |
| 15 | |
| 16 | # Use version from .nvmrc in current directory |
| 17 | nvm use |
.nvmrc file (place in project root)text
| 1 | 22 |
Add nvm use to your shell profile or use a shell hook to auto-switch versions when you cd into a project with a .nvmrc file.