πŸ’‘ Tip: Don't install Node.js directly using apt or Snap. Use NVM β€” Node Version Manager β€” instead.
It’s cleaner, safer, and perfect for developers!


πŸ” What is NVM?

NVM (Node Version Manager) is a tool that helps you install, manage, and switch between different versions of Node.js easily β€” without affecting system-wide settings.


βœ… Why Use NVM Instead of Direct Installation?

Here’s why using NVM is a better choice:

  1. Switch Node versions anytime – Perfect for different projects.
  2. No root access needed – Avoids system-level changes.
  3. Easily uninstall or upgrade – Clean and flexible.
  4. Avoid outdated versions – apt install nodejs often gives older versions.
  5. No conflict with OS packages – Keeps things isolated and safer.

πŸ› οΈ Step-by-Step Guide to Install NVM & Node.js

Step 1: Install NVM (Latest Version)

Open your terminal and run:

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

☝️ This downloads and runs the official NVM installation script.


Step 2: Load NVM in Your Shell

After installation, activate NVM by running:

source ~/.bashrc

πŸ”„ This command reloads your shell configuration so NVM is available immediately.


Step 3: Confirm NVM Installation

Check if NVM was installed correctly:

nvm --version

If you see a version number like 0.39.7, you're good to go!


Step 4: Install Latest Stable Node.js (v20)

nvm install 20

🎯 This installs Node.js version 20 (LTS) using NVM.


Step 5: Set Node v20 as the Default Version

nvm alias default 20

πŸ“Œ This makes Node v20 the default every time you open a new terminal.


Step 6: Use Node v20 Right Now

nvm use 20

🟒 Activates Node v20 in your current terminal session.


Step 7: Confirm Node and NPM Installation

node -v
npm -v

You should see the versions for Node (v20.x.x) and NPM.


πŸ”š You’re Done!

πŸŽ‰ That’s it! You’ve installed Node.js the right way using NVM.

Now you can:

  • Easily switch Node versions: nvm use 18, nvm install 21, etc.
  • Keep your system clean and organized.
  • Stay up-to-date with latest LTS releases.