Managing Node.js Versions with nvm
Check Current Versions
node --version
npm --version
Installing nvm
If you don’t have nvm installed, you can install it using:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Restart your terminal after installation.
Basic nvm Commands
List Installed Node.js Versions
nvm ls
List Available Node.js Versions
nvm ls-remote
Install a Specific Version
nvm install <version> # e.g., nvm install 18.18.0
Switch to a Specific Version
nvm use <version> # e.g., nvm use 18.18.0
Set Default Version
This will be used in new terminal sessions:
nvm alias default <version> # e.g., nvm alias default 18.18.0
Check Current Version
node --version
npm --version
Example Workflow
- Check current version:
node --version
- List installed versions:
nvm ls
- Install a new version:
nvm install 18.18.0
- Switch to it:
nvm use 18.18.0
- Make it default:
nvm alias default 18.18.0
Notes
- Use LTS versions for production
- Different projects can use different Node.js versions
- Global packages need to be reinstalled when switching versions