Installation Guide

Learn how to install and configure npm on your system

guide

npm Installation Guide

Learn how to install and configure npm on your system.

Prerequisites

Before installing npm, you need to have Node.js installed on your system. npm comes bundled with Node.js, so installing Node.js will automatically install npm.

Installation Methods

Method 1: Install via Node.js (Recommended)

The easiest way to install npm is by installing Node.js, which includes npm:

  1. Visit the official Node.js website: Go to nodejs.org
  2. Download the LTS version: Choose the Long Term Support (LTS) version for stability
  3. Run the installer: Follow the installation wizard
  4. Verify installation: Open your terminal and run:
node --version
npm --version

Method 2: Install via Package Manager

macOS (using Homebrew)

brew install node

Ubuntu/Debian

sudo apt update
sudo apt install nodejs npm

Windows (using Chocolatey)

choco install nodejs

Method 3: Install via Node Version Manager

For managing multiple Node.js versions, use a version manager:

nvm (Node Version Manager)

# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# Install latest Node.js
nvm install node
nvm use node

Configuration

After installation, you can configure npm:

Set Default Registry

npm config set registry https://registry.npmjs.org/

Set Default Directory

npm config set prefix ~/.npm-global

Update npm

npm install -g npm@latest

Troubleshooting

Permission Issues

If you encounter permission errors, you may need to:

  1. Change npm's default directory:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
  1. Add to your PATH (add to ~/.bashrc or ~/.zshrc):
export PATH=~/.npm-global/bin:$PATH

Clear npm Cache

npm cache clean --force

Next Steps

Once npm is installed, you can:

Resources