pnpm (performant npm) is a blazing-fast, disk-space efficient package manager for Node.js. Unlike npm or yarn, it uses a content-addressable store to avoid duplicate packages, saving gigabytes of disk space while maintaining superior performance.
#Installation Guide
#macOS & Linux
# Using the install script
curl -fsSL https://get.pnpm.io/install.sh | sh-
# Using Homebrew (macOS)
brew install pnpm
# Using npm (if you already have Node.js)
npm install -g pnpm
#Windows
# Using PowerShell
iwr https://get.pnpm.io/install.ps1 -useb | iex
# Using Chocolatey
choco install pnpm
# Using npm (Command Prompt or PowerShell)
npm install -g pnpm
#Verifying Your Installation
After installation, verify everything is working correctly:
# Check pnpm version
pnpm --version
# Example output: 9.15.0
# Get detailed version information
pnpm -v
# Shows: pnpm, Node.js, and platform info
# Check installation location
which pnpm # macOS/Linux
where pnpm # Windows
#Keeping pnpm Updated
Keep your package manager current with these commands:
# Update to the latest version
pnpm add -g pnpm
# Update to a specific version
pnpm add -g pnpm@10.19.0
# Check current version vs latest
pnpm --version
# Compare with: https://github.com/pnpm/pnpm/releases
#Essential Commands with Examples
Project Initialization
# Create a new project
pnpm init
# Initialize with TypeScript configuration
pnpm init && pnpm add -D typescript @types/node
# Create a Next.js project
pnpm create next-app my-app
Package Management
# Install all dependencies from package.json
pnpm install
# Or use the shorthand:
pnpm i
# Add production dependency
pnpm add express lodash
# Add specific version
pnpm add react@18.2.0
# Add development dependency
pnpm add -D typescript @types/node eslint
# Add global package
pnpm add -g @angular/cli
# Install peer dependencies automatically
pnpm add --save-peer react react-dom
Dependency Management
# Update all packages to latest within version ranges
pnpm update
# Update specific package
pnpm update react
# Update to latest major versions (use with caution!)
pnpm update --latest
# Remove a package
pnpm remove axios
# Check for outdated packages
pnpm outdated
Script Execution
# Run scripts defined in package.json
pnpm start
pnpm test
pnpm run build
# Pass arguments to scripts
pnpm dev --port 3000
pnpm test --watch --coverage
# List all available scripts
pnpm run
#Execute single command without adding to package.json
pnpm exec vite build
#Workspaces (Monorepo Support)
Initialize workspace in monorepo
pnpm init
# Add package to workspace
pnpm add axios --filter my-package
# Run script across all packages
pnpm --recursive run build
#Install dependencies in all packages
pnpm --recursive install
Performance Optimization
#Install without optional dependencies (faster)
pnpm install --no-optional
# Skip running lifecycle scripts
pnpm install --ignore-scripts
# Clear pnpm store (free up space)
pnpm store prune
Configuration Examples
// .npmrc configuration for pnpm
shamefully-hoist=true
strict-peer-dependencies=false
auto-install-peers=true
Why Choose pnpm? Disk Space Efficiency: Uses hard links and symlinks to share packages
Speed: Faster than npm and yarn in most scenarios
Strict: Prevents phantom dependencies by default
Monorepo Friendly: Built-in workspace support
Security: Uses checksums to verify package integrity
Migration Tips bash
#Migrate from npm/yarn
rm -rf node_modules package-lock.json yarn.lock
pnpm import # Converts package-lock.json or yarn.lock
pnpm install
#Or start fresh:
rm -rf node_modules
pnpm install
Troubleshooting Common Issues
# If permissions error occurs (macOS/Linux)
sudo chown -R $(whoami) ~/.pnpm-store
# Clear cache
pnpm store prune
# Check for broken dependencies
pnpm doctor
# Verify store integrity
pnpm store status