learn.colinkim.dev

npm and pnpm: global tools vs local tools

Learn when to install packages globally and when to keep them local to a project.

Most packages should be installed locally in a project. Some tools, however, are meant to be used across all projects on your system. Understanding the difference prevents confusion and keeps your projects reliable.

Local installs are the default

When you run npm install react or pnpm add react in a project, the package installs locally. It:

  • Goes in that project’s node_modules
  • Is recorded in that project’s package.json
  • Is available only within that project

This is what you want for nearly all dependencies. It keeps each project isolated and reproducible.

Run this in a project directory:

npm install react

Or with pnpm:

pnpm add react

Now react is available to this project, but not to other projects.

When to use global installs

Global packages are installed once for your entire system. They are available in your terminal from any directory.

Install a package globally:

npm install --global create-vite

Or with pnpm:

pnpm add --global create-vite

Common global tools:

  • Project scaffolding: create-vite, create-react-app, create-next-app
  • CLI utilities: vercel, netlify-cli, heroku
  • Development tools: typescript (for tsc CLI), eslint (for global linting)
  • Package managers: corepack (for managing pnpm versions)

The pattern is: global tools create, manage, or operate on projects, but are not used within project code.

Checking globally installed packages

To see what packages are installed globally:

npm list --global --depth=0

pnpm:

pnpm list --global

This shows which global packages you have and their versions.

Removing global packages

To remove a global package:

npm uninstall --global <package>

pnpm:

pnpm remove --global <package>

Corepack and pnpm

Corepack is a tool that ships with Node.js to manage package manager versions. It is meant to be installed globally:

npm install --global corepack@latest

Then enable pnpm:

corepack enable pnpm

This sets up pnpm as a global command. To pin a pnpm version in your project:

corepack use pnpm@latest-10

This adds "packageManager": "pnpm@10.x.x" to your package.json, which helps your team use the same pnpm version.

A simple rule

  • Is the package required by your project’s code? → Install it locally
  • Is the package a tool for creating or managing projects? → Install it globally

Following this rule keeps your projects reproducible and avoids version conflicts.

Quick Check

One answer

Which is the stronger default for a tool your project depends on, like ESLint or Vite?

Choose the best answer and use it to track your progress through the lesson.

Progress

Quick checks

No quick checks in this lesson.

Mark lesson manually or answer quick checks to track progress.