Find us on social media
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 | bashReload your shell:
bash
source ~/.bashrcStep 2 — Install Node.js
Install the latest LTS version:
bash
nvm install --ltsOr install a specific version:
bash
nvm install 20
nvm install 18Step 3 — Verify the installation
bash
node --version
npm --versionStep 4 — Switch between versions
bash
nvm use 20
nvm use 18
nvm alias default 20 # Set default versionStep 5 — Install global packages
bash
npm install -g pm2 # Process manager
npm install -g yarn # Alternative package manager
npm install -g typescript # TypeScript compilerList installed versions
bash
nvm lsUse a .nvmrc file
Create a .nvmrc in your project root:
bash
echo "20" > .nvmrcThen simply run:
bash
nvm useAlternative: 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 -yNote
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?