Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.

Get Started Now!

How to Install Node.js and npm (Step-by-Step Guide)

laravelPHP Tutorials

How to Install Node.js and npm (Step-by-Step Guide)

Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine, and npm (Node Package Manager) is the package manager for Node.js. Here’s how to install them on various operating systems:

For Windows

Method 1: Using the Official Installer

  1. Download the installer:
  • Download the LTS (Long Term Support) version (recommended for most users)

2. Run the installer:

    • Double-click the downloaded .msi file
    • Follow the installation wizard (you can accept all defaults)

    3. Verify installation:

      • Open Command Prompt (cmd)
      • Type
      node -v
      npm -v
      • This should display the installed versions

      Method 2: Using Chocolatey (Package Manager)

      1. Install Chocolatey (if you don’t have it):
         @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
      1. Install Node.js:
         choco install nodejs

      For macOS

      Method 1: Using Official Installer

      1. Download the installer from Node.js website
      2. Run the installer and follow the prompts
      3. Verify installation in Terminal:
         node -v
         npm -v

      Method 2: Using Homebrew

      1. Install Homebrew (if you don’t have it):
         /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      1. Install Node.js:
         brew install node

      For Linux (Ubuntu/Debian)

      Method 1: Using NodeSource PPA (Recommended)

      1. Install curl (if not already installed):
         sudo apt-get install curl
      1. Add NodeSource repository:
         curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

      (Replace lts with the version number you want if needed)

      1. Install Node.js and npm:
         sudo apt-get install -y nodejs
      1. Verify installation:
         node -v
         npm -v

      Method 2: Using Package Manager

      sudo apt update
      sudo apt install nodejs npm

      Post-Installation Steps (All OS)

      1. Update npm (optional but recommended):
         npm install -g npm@latest
      1. Check for global npm permissions:
      • If you get permission errors, you might need to:
        • Reinstall with a version manager (like nvm)
        • Change npm’s default directory
        • Use sudo (not recommended for security reasons)

      Optional: Install Using Node Version Manager (nvm)

      nvm allows you to install and switch between multiple Node.js versions:

      1. Install nvm:
      • Linux/macOS:
        curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
      • Windows: Use nvm-windows
      1. Install Node.js:
         nvm install --lts
      1. Use a specific version:
         nvm use 14.17.0

      That’s it! You now have Node.js and npm installed on your system. You can start creating Node.js applications or install packages using npm.

      Subscribe
      Notify of
      guest
      0 Comments
      Oldest
      Newest Most Voted
      0
      Would love your thoughts, please comment.x
      ()
      x