Installing Node.js on Linux (Ubuntu/CentOS): A Comprehensive Guide

Learn how to install Node.js and npm on popular Linux distributions like Ubuntu and CentOS. This tutorial provides detailed, step-by-step instructions, covering various installation methods and troubleshooting common issues for a smooth and successful Node.js setup on your Linux system.



Installing Node.js on Linux (Ubuntu/CentOS)

This guide explains how to install Node.js on various Linux distributions, including Ubuntu and CentOS. The steps might vary slightly depending on your specific distribution.

Installing Node.js on Ubuntu

Here's how to install Node.js and npm (Node Package Manager) on Ubuntu:

  1. Open the Terminal: Use the keyboard shortcut (Ctrl+Alt+T).
  2. Install `python-software-properties` (if not already installed):
  3. Install python-software-properties
    
    sudo apt-get install python-software-properties
                    
  4. Add the Node.js PPA (Personal Package Archive):
  5. Add Node.js PPA
    
    sudo apt-add-repository ppa:chris-lea/node.js
                    

    Press Enter after each command. You may be prompted to press Enter again to continue.

  6. Update the package list:
  7. Update Package List
    
    sudo apt-get update
                    

    (This might take a few moments.)

  8. Install Node.js and npm:
  9. Install Node.js and npm
    
    sudo apt-get install nodejs npm
                    

    (Some distributions might require a separate `sudo apt-get install nodejs` command.)

  10. Verify the Installation: Check the versions of Node.js and npm:
  11. Verify Installation
    
    node --version
    npm -v
                    
  12. View Installed Packages: (Optional) Use this command to see all installed packages, including Node.js:
  13. View Installed Packages
    
    dpkg --get-selections
                    

You'll need administrator privileges (using `sudo`) for these commands. CentOS and other distributions will have slightly different package managers (e.g., `yum` instead of `apt-get`), but the general principles remain the same; consult your distribution's documentation for specific instructions.

next →

← prev