Dung (Donny) Nguyen

Senior Software Engineer

Install Node.js on Ubuntu

To install Node.js on Ubuntu, the most flexible and recommended method is using NVM (Node Version Manager). This lets you easily switch between Node.js versions.

Here’s a breakdown of the three main installation methods:


This method is ideal if you want to manage multiple Node.js versions or avoid system-wide changes.

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

    Then restart your terminal or run:

    source ~/.nvm/nvm.sh
    
  2. Install Node.js via NVM:
    nvm install node        # Latest version
    nvm install 20          # Specific version (e.g., v20)
    nvm use 20              # Switch to version 20
    
  3. Verify installation:
    node -v
    npm -v
    

📦 Method 2: Using Ubuntu’s APT Package Manager

This is the simplest method but may not give you the latest version.

  1. Update package index:
    sudo apt update
    
  2. Install Node.js and npm:
    sudo apt install nodejs npm
    
  3. Check versions:
    node -v
    npm -v
    

📥 Method 3: Using NodeSource PPA (for specific versions)

This method is good for installing a specific version system-wide.

  1. Add NodeSource PPA:
    curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
    
  2. Install Node.js:
    sudo apt install -y nodejs
    
  3. Verify installation:
    node -v
    npm -v
    

🔍 Bonus Tips

Install Yarn