Using Node Version Manager nvm

NVM (Node Version Manager) is a command-line tool that allows you to easily install, manage, and switch between multiple versions of Node.js on a single machine. It’s especially useful for developers who work on projects requiring different Node.js versions, ensuring compatibility and simplifying environment setup.

✅ Why Use nvm?

  • Install and manage multiple Node.js versions side by side
  • Switch between versions per project, shell, or system
  • No need for sudo or modifying system Node
  • Compatible with most POSIX-compliant shells

1. Install nvm

On macOS or Linux, run:

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

Then add the following to your shell profile (.bashrc, .zshrc, etc.) if the installer hasn’t already:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Reload your shell or run:

source ~/.bashrc

Verify installation:

command -v nvm
nvm --version

2. List Available & Install Versions

nvm ls-remote                 # Show available Node.js versions
nvm install 18.17.0           # Install specific version
nvm install --lts             # Install latest LTS version
nvm install node              # Install latest current version

3. View & Switch Installed Versions

nvm ls                        # List installed versions
nvm use 18.17.0               # Switch to a specific version
nvm use --lts                 # Use latest LTS version
nvm current                   # Show current active version
node -v                       # Confirm active Node version

4. Set a Default Version

nvm alias default 18.17.0     # Set default version for new shells

5. Manage Versions and Aliases

nvm uninstall 16.20.0         # Remove a version
nvm alias myproj 18           # Create a custom alias
nvm unalias myproj            # Remove custom alias
nvm use system                # Revert to system-installed Node