Course contentsShow
← JavaScript
Lesson 2487 of 2,72351. Package ManagementFree lesson

Local vs Global Installations

The difference between local project dependencies and globally installed CLI tools.

Local vs Global Installations

You'll learn how to decide whether to install an npm package locally in a project or globally on your system, and why that distinction matters.

Two Places, Two Purposes

When you install a package with npm install, it can go in one of two places:

  • Local (project-level): Installed in the current project's node_modules folder. Only available to that project.
  • Global (system-level): Installed once on your machine, accessible from anywhere in your terminal.

Think of it like tools in a workshop. Local installations are like project-specific supplies you keep in a toolbox for one job—they travel with that job. Global installations are like power tools mounted on the wall that you use across many different projects.

When to Use Each

Local installations (default):

npm install lodash

This is what you want for project dependencies—libraries your code imports and uses. Every collaborator who clones your project gets the same versions because they're listed in package.json and installed in node_modules.

Global installations:

npm install -g create-react-app

Use the -g flag for command-line tools you want to run from anywhere—think build tools, scaffolding utilities, or developer utilities. These provide terminal commands, not importable code.

Why This Matters

Local installations ensure reproducibility—your project always works with tested versions. Global installations avoid redundancy for CLI tools you use everywhere.

Mixing them up causes confusion: globally installing a project dependency means it won't be tracked in package.json, breaking the project for others. Locally installing a CLI tool means you can't run its commands directly.

Key Takeaway: Install project dependencies locally (default npm install) so they're tracked and versioned. Install CLI tools globally (npm install -g) when you need them accessible system-wide.