Node.js installation process


Installing Node.js involves setting up the runtime environment on your system so you can start building and running Node.js applications. Here’s a step-by-step guide to installing Node.js on various operating systems:

1. Installation on Windows

Using the Node.js Installer

  1. Download the Installer:

    • Go to the Node.js official website.
    • Click on the “Downloads” tab.
    • Choose the Windows installer (.msi) for the LTS (Long-Term Support) or Current version, depending on your needs.
  2. Run the Installer:

    • Double-click the downloaded .msi file.
    • Follow the prompts in the Node.js Setup Wizard. You can accept the default options.
    • Make sure to check the box that says "Automatically install the necessary tools" if you need build tools like Python.
  3. Verify Installation:

    • Open the Command Prompt (cmd) or PowerShell.
    • Run the following commands to verify Node.js and npm (Node Package Manager) are installed correctly:
      node -v npm -v
    • These commands will display the version numbers if the installation was successful.

2. Installation on macOS

Using the Node.js Installer

  1. Download the Installer:

    • Visit the Node.js official website.
    • Click on the “Downloads” tab.
    • Download the macOS installer (.pkg) for the LTS or Current version.
  2. Run the Installer:

    • Double-click the downloaded .pkg file.
    • Follow the instructions in the installation wizard.
  3. Verify Installation:

    • Open the Terminal.
    • Run the following commands to check the Node.js and npm versions:
      node -v npm -v

Using Homebrew (Alternative Method)

  1. Install Homebrew (if not already installed):

    • Open Terminal and run:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Node.js:

    • Run:
      brew install node
  3. Verify Installation:

    • Check the Node.js and npm versions:
      node -v npm -v

3. Installation on Linux

Using a Package Manager

For Ubuntu/Debian-based Distributions:

  1. Update the Package Index:

    • Open Terminal and run:
      sudo apt update
  2. Install Node.js:

    • You can install Node.js from the official repository:
      sudo apt install nodejs sudo apt install npm
  3. Verify Installation:

    • Check the installed versions:
      node -v npm -v

For Fedora/RHEL-based Distributions:

  1. Install Node.js:

    • Open Terminal and run:
      sudo dnf install nodejs
  2. Verify Installation:

    • Check the Node.js and npm versions:
      node -v npm -v

Using Node Version Manager (nvm)

nvm allows you to manage multiple Node.js versions on your machine.

  1. Install nvm:

    • Open Terminal and run:
      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
  2. Load nvm:

    • Run:
      source ~/.bashrc
    • or for zsh:
      source ~/.zshrc
  3. Install Node.js Using nvm:

    • List available versions:
      nvm ls-remote
    • Install a specific version (e.g., 16.20.0):
      nvm install 16.20.0
    • Set a default version:
      nvm alias default 16.20.0
  4. Verify Installation:

    • Check the Node.js and npm versions:
      node -v npm -v

4. Post-Installation

After installing Node.js, you might want to:

  • Install Global Packages: Use npm to install global packages:
    npm install -g <package-name>
  • Set Up a Project: Create a new Node.js project with:
    mkdir my-project cd my-project npm init

Summary

  • Windows: Use the .msi installer from the Node.js website.
  • macOS: Use the .pkg installer or Homebrew.
  • Linux: Use the package manager or nvm for multiple versions.
  • Verify: Use node -v and npm -v to confirm installation.