To install Node.js using NVM (Node Version Manager) on Linux, follow these steps:

Step 1: Install NVM

  1. Open your terminal.
  2. Run the following command to download and install NVM:
    curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    
    🔹 Replace v0.39.7 with the latest NVM version from the NVM GitHub.
  3. Reload your shell configuration to apply changes:
    source ~/.bashrc  # For Bash users
    source ~/.zshrc   # For Zsh users
    
  4. Verify NVM installation:
    nvm --version
    
    If NVM is installed correctly, you’ll see its version number.

Step 2: Install Node.js Using NVM

  1. List available Node.js versions:
    nvm ls-remote
    
  2. Install the latest stable Node.js version:
    nvm install --lts
    
    OR, install a specific version (e.g., 20.14.0):
    nvm install 20.14.0
    
  3. Verify the installation:
    node -v
    npm -v
    

Step 3: Set Default Node.js Version

If you have multiple Node.js versions, set a default version:
nvm use 20.14.0  # Use specific version
nvm alias default 20.14.0  # Set it as default

Step 4: Check Installed Node.js Versions

List all installed Node.js versions:
nvm ls

Step 5: Uninstall Node.js (If Needed)

To remove a specific Node.js version:
nvm uninstall 20.14.0

Bonus: Install Yarn (Optional)

If you need Yarn (a package manager alternative to npm), install it with:
npm install --global yarn
Verify with:
yarn -v