Node.jsNVMJavaScript5 min read

Install Node.js with NVM

Install Node.js with NVM to manage multiple versions and set up your development environment.


NVM (Node Version Manager) lets you install and switch between multiple Node.js versions easily. This is the recommended approach for development and production.

Step 1 — Install NVM

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

Reload your shell:

bash
source ~/.bashrc

Step 2 — Install Node.js

Install the latest LTS version:

bash
nvm install --lts

Or install a specific version:

bash
nvm install 20
nvm install 18

Step 3 — Verify the installation

bash
node --version
npm --version

Step 4 — Switch between versions

bash
nvm use 20
nvm use 18
nvm alias default 20  # Set default version

Step 5 — Install global packages

bash
npm install -g pm2        # Process manager
npm install -g yarn       # Alternative package manager
npm install -g typescript # TypeScript compiler

List installed versions

bash
nvm ls

Use a .nvmrc file

Create a .nvmrc in your project root:

bash
echo "20" > .nvmrc

Then simply run:

bash
nvm use

Alternative: Install via NodeSource

If you prefer a system-wide installation without NVM:

bash
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install nodejs -y

Note

NVM installs Node.js per user. If you need Node.js available system-wide (for example, for systemd services), use the NodeSource method or create a symlink to the NVM binary.


Was this guide helpful?