Home·Terminal commands

npm install

Packages and runtimes

Usage

npm install [<package>] [-D|-g]

Downloads the dependencies package.json asks for into node_modules and updates package-lock.json; since npm 7 peer dependencies are installed too, and --production was replaced by --omit=dev.

Common flags

FlagMeaning
-Dsave as a devDependency
-ginstall globally, onto PATH
-Esave the exact version, without a caret
--omit=devskip devDependencies; replaces the old --production
--legacy-peer-depsignore peer conflicts the way npm 6 did
--ignore-scriptsdo not run install scripts
--forceoverwrite cache and conflict checks

Examples

npm install

installs what package.json asks for and updates package-lock.json

npm install -D vitest

adds a dev-only dependency

npm install react@18.3.1

installs one exact version and records it

The question is always what goes where: inside this project, or on the whole machine.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does npm install do?

Downloads the dependencies package.json asks for into node_modules and updates package-lock.json; since npm 7 peer dependencies are installed too, and --production was replaced by --omit=dev.

Q. How do I type it?

npm install [<package>] [-D|-g] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man npm. This command sits under Packages and runtimes.

Related commands

man page: man npm-install