Global Packages
A global install (npm install -g) places a package's executables on your system PATH so you can run them from any directory — not tied to one project. It is the right tool for daily-driver CLIs, and the wrong tool for project dependencies. Knowing the difference avoids the classic "works on my machine" trap.
Local vs global
Local (default) | Global ( | |
|---|---|---|
Installs to |
| A system-wide prefix |
Recorded in package.json | Yes | No — invisible to your project |
Available from | The project (and its scripts) | Anywhere on your machine |
Reproducible across machines | Yes (via lockfile) | No |
Use for | Everything a project depends on | Personal CLIs you run constantly |
Installing and managing globals
npm install -g pnpm typescript # install global CLIs npm list -g --depth=0 # list what you've installed globally npm outdated -g # which globals have updates npm update -g # update all globals npm uninstall -g typescript # remove one npm root -g # print the global node_modules path npm prefix -g # print the global install prefix
$ npm list -g --depth=0 /usr/local/lib ├── npm@10.5.0 ├── pnpm@9.1.0 └── typescript@5.4.5
Where globals actually live
Global binaries land in a bin directory that is on your PATH; the package code sits in a global node_modules. The exact location depends on how Node was installed:
Typical global prefixes
nvm-managed Node : ~/.nvm/versions/node/<ver>/bin ← changes per Node version! Homebrew (mac) : /opt/homebrew/bin or /usr/local/bin Linux (system) : /usr/local/bin (may need sudo — see warning) Windows : %AppData%\npm
Never use sudo to fix permission errors
What belongs global — and what does not
Global is fine for: version managers (
pnpm,nodemon), personal scaffolding helpers, system utilities you invoke from any folder.Never global for project deps: a teammate cloning your repo has no idea you
-ginstalled something — it is not inpackage.json, so their build fails.Prefer
npxfor one-offs: scaffolders and rarely-used tools should run via npx, not clutter your global space with stale versions.Prefer local + scripts for build tools:
typescript,eslint,jestbelong indevDependenciesso the version is pinned and shared.