Install NVM (Node Version Manager) and Node.js
NVM is a tool for managing multiple versions of Node.js. It allows you to install, switch between, and manage different versions of Node.js and NPM (Node Package Manager) easily.
Official pages
Install on Linux or macOS
1. Download and install NVM
1.1 Prepare the runtime directory for NVM
# Create runtime directory for NVM:
mkdir -vp ~/workspaces/runtimes/.nvm
# Set and export `NVM_DIR` environment variable:
export NVM_DIR="${HOME}/workspaces/runtimes/.nvm"
1.2 Install NVM
# Get the latest release version of NVM:
export NVM_VERSION=$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep "tag_name" | cut -d\" -f4)
# Install or update NVM:
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/install.sh" | bash
## Load NVM into the current shell session:
# For bash:
source ~/.bashrc
# For zsh:
source ~/.zshrc
1.3 Verify NVM installation
2. Install Node.js and NPM
2.1 Create a new Node.js environment
# Install Node.js, update NPM to latest, and set environment name to `default` (change node.js version as needed):
nvm install --latest-npm --alias=default 24.12.0
# Set nvm to use `default` node.js environment:
nvm use default
# Clean NVM caches:
nvm cache clear