LinuxCommandLibrary

npm-install

TLDR

Install all dependencies

$ npm install
copy
Install specific package
$ npm install [package]
copy
Install as dev dependency
$ npm install -D [package]
copy
Install specific version
$ npm install [package]@[version]
copy
Install globally
$ npm install -g [package]
copy
Install from git
$ npm install [git+https://github.com/user/repo.git]
copy
Clean install (CI)
$ npm ci
copy

SYNOPSIS

npm install [options] [packages...]

DESCRIPTION

npm install (or npm i) installs packages and their dependencies. Without arguments, it installs everything in package.json. With package names, it adds them to the project.
The package-lock.json ensures reproducible installs.

PARAMETERS

-D, --save-dev

Save as devDependency.
-g, --global
Install globally.
-E, --save-exact
Save exact version.
--no-save
Don't update package.json.
--legacy-peer-deps
Ignore peer dep conflicts.
--force
Force fetch packages.

VERSION RANGES

$ npm install lodash         # Latest
npm install lodash@4.17.0  # Exact
npm install lodash@^4.0.0  # Compatible
npm install lodash@~4.17.0 # Patch updates
copy

CAVEATS

npm ci is faster for CI/CD. Peer deps may cause issues in npm 7+. Lock file should be committed.

HISTORY

npm install has been the core command of npm since Isaac Schlueter created npm in 2010 for Node.js package management.

SEE ALSO

npm(1), npm-ci(1), npm-uninstall(1), yarn(1)

Copied to clipboard