adnenre
#Node.js#tools#JavaScript

Getting Started with NVM: The Essential Node.js Version Manager

Learn how to install, manage, and switch between Node.js versions seamlessly with NVM

NVM (Node Version Manager) is an indispensable tool for JavaScript developers that allows you to install, manage, and switch between multiple Node.js versions on a single machine. Unlike installing Node.js directly, nvm gives you complete control over your development environment, making it easy to work on projects with different Node.js requirements.

#Installation Guide

#macOS & Linux

# Using the install script (recommended)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

# Or using wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

# After installation, restart your terminal or source your shell profile
source ~/.bashrc    # For bash
source ~/.zshrc     # For zsh

#Installation verification

Verify installation

# Check nvm version
nvm --version
# Example output: 0.40.0

# Check if nvm is properly loaded
command -v nvm
# Should output: nvm

# Get help with available commands
nvm --help

#Version

Version Managment

# List all installed Node.js versions
nvm ls

# List all available Node.js versions
nvm ls-remote

# List available LTS versions
nvm ls-remote --lts

# Use a specific version
nvm use 18.19.0

# Set default Node.js version
nvm alias default 20.11.0

# Run a specific command with a Node.js version
nvm run 16.20.2 app.js

# Execute arbitrary command in a subshell with the specified version
nvm exec 18.19.0 node --version

# Check which version is currently being used
nvm current

# Uninstall a version
nvm uninstall 14.21.3

Share this post