.TH "NPM\-INSTALL" "1" "November 2022" "9.1.1" .SH "NAME" \fBnpm-install\fR .SH Synopsis .SH Description .P This command installs a package and any packages that it depends on\. If the .br package has a package\-lock, or an npm shrinkwrap file, or a yarn lock file, .br the installation of dependencies will be driven by that, respecting the .br following order of precedence: .RS 1 .IP \(bu 2 \fBnpm\-shrinkwrap\.json\fP .IP \(bu 2 \fBpackage\-lock\.json\fP .IP \(bu 2 \fByarn\.lock\fP .RE .P See package\-lock\.json and .br \fBnpm shrinkwrap\fP\|\. .P A \fBpackage\fP is: .RS 1 .IP \(bu 2 a) a folder containing a program described by a .br \fBpackage\.json\fP file .IP \(bu 2 b) a gzipped tarball containing (a) .IP \(bu 2 c) a url that resolves to (b) .IP \(bu 2 d) a \fB@\fP that is published on the registry (see .br \fBregistry\fP) with (c) .IP \(bu 2 e) a \fB@\fP (see \fBnpm dist\-tag\fP) that .br points to (d) .IP \(bu 2 f) a \fB\fP that has a "latest" tag satisfying (e) .IP \(bu 2 g) a \fB\fP that resolves to (a) .RE .P Even if you never publish your package, you can still get a lot of benefits .br of using npm if you just want to write a node program (a), and perhaps if .br you also want to be able to easily install it elsewhere after packing it up .br into a tarball (b)\. .RS 1 .IP \(bu 2 \fBnpm install\fP (in a package directory, no arguments): .P Install the dependencies to the local \fBnode_modules\fP folder\. .P In global mode (ie, with \fB\-g\fP or \fB\-\-global\fP appended to the command), .br it installs the current package context (ie, the current working .br directory) as a global package\. .P By default, \fBnpm install\fP will install all modules listed as .br dependencies in \fBpackage\.json\fP\|\. .P With the \fB\-\-production\fP flag (or when the \fBNODE_ENV\fP environment .br variable is set to \fBproduction\fP), npm will not install modules listed .br in \fBdevDependencies\fP\|\. To install all modules listed in both .br \fBdependencies\fP and \fBdevDependencies\fP when \fBNODE_ENV\fP environment .br variable is set to \fBproduction\fP, you can use \fB\-\-production=false\fP\|\. .QP .P NOTE: The \fB\-\-production\fP flag has no particular meaning when adding a .br dependency to a project\. . .IP \(bu 2 \fBnpm install \fP: .P If \fB\fP sits inside the root of your project, its dependencies will be installed and may .br be hoisted to the top\-level \fBnode_modules\fP as they would for other .br types of dependencies\. If \fB\fP sits outside the root of your project, .br \fInpm will not install the package dependencies\fR in the directory \fB\fP, .br but it will create a symlink to \fB\fP\|\. .QP .P NOTE: If you want to install the content of a directory like a package from the registry instead of creating a link, you would need to use the \fB\-\-install\-links\fP option\. . .P Example: .RS 2 .nf npm install \.\./\.\./other\-package \-\-install\-links npm install \./sub\-package .fi .RE .IP \(bu 2 \fBnpm install \fP: .P Install a package that is sitting on the filesystem\. Note: if you just .br want to link a dev directory into your npm root, you can do this more .br easily by using \fBnpm link\fP\|\. .P Tarball requirements: .RS 1 .IP \(bu 2 The filename \fImust\fR use \fB\|\.tar\fP, \fB\|\.tar\.gz\fP, or \fB\|\.tgz\fP as the .br extension\. .IP \(bu 2 The package contents should reside in a subfolder inside the tarball .br (usually it is called \fBpackage/\fP)\. npm strips one directory layer .br when installing the package (an equivalent of \fBtar x \-\-strip\-components=1\fP is run)\. .IP \(bu 2 The package must contain a \fBpackage\.json\fP file with \fBname\fP and .br \fBversion\fP properties\. .RE .P Example: .RS 2 .nf npm install \./package\.tgz .fi .RE .IP \(bu 2 \fBnpm install \fP: .P Fetch the tarball url, and then install it\. In order to distinguish between .br this and other options, the argument must start with "http://" or "https://" .P Example: .RS 2 .nf npm install https://github\.com/indexzero/forever/tarball/v0\.5\.6 .fi .RE .IP \(bu 2 \fBnpm install [<@scope>/]\fP: .P Do a \fB@\fP install, where \fB\fP is the "tag" config\. (See .br \fBconfig\fP\|\. The config's default value is \fBlatest\fP\|\.) .P In most cases, this will install the version of the modules tagged as .br \fBlatest\fP on the npm registry\. .P Example: .RS 2 .nf npm install sax .fi .RE .P \fBnpm install\fP saves any specified packages into \fBdependencies\fP by default\. .br Additionally, you can control where and how they get saved with some .br additional flags: .RS 1 .IP \(bu 2 \fB\-P, \-\-save\-prod\fP: Package will appear in your \fBdependencies\fP\|\. This .br is the default unless \fB\-D\fP or \fB\-O\fP are present\. .IP \(bu 2 \fB\-D, \-\-save\-dev\fP: Package will appear in your \fBdevDependencies\fP\|\. .IP \(bu 2 \fB\-O, \-\-save\-optional\fP: Package will appear in your .br \fBoptionalDependencies\fP\|\. .IP \(bu 2 \fB\-\-no\-save\fP: Prevents saving to \fBdependencies\fP\|\. .RE .P When using any of the above options to save dependencies to your .br package\.json, there are two additional, optional flags: .RS 1 .IP \(bu 2 \fB\-E, \-\-save\-exact\fP: Saved dependencies will be configured with an .br exact version rather than using npm's default semver range operator\. .IP \(bu 2 \fB\-B, \-\-save\-bundle\fP: Saved dependencies will also be added to your .br \fBbundleDependencies\fP list\. .RE .P Further, if you have an \fBnpm\-shrinkwrap\.json\fP or \fBpackage\-lock\.json\fP .br then it will be updated as well\. .P \fB\fP is optional\. The package will be downloaded from the registry .br associated with the specified scope\. If no registry is associated with .br the given scope the default registry is assumed\. See .br \fBscope\fP\|\. .P Note: if you do not include the @\-symbol on your scope name, npm will .br interpret this as a GitHub repository instead, see below\. Scopes names .br must also be followed by a slash\. .P Examples: .RS 2 .nf npm install sax npm install githubname/reponame npm install @myorg/privatepackage npm install node\-tap \-\-save\-dev npm install dtrace\-provider \-\-save\-optional npm install readable\-stream \-\-save\-exact npm install ansi\-regex \-\-save\-bundle .fi .RE .P \fBNote\fR: If there is a file or folder named \fB\fP in the current .br working directory, then it will try to install that, and only try to .br fetch the package by name if it is not valid\. .IP \(bu 2 \fBnpm install @npm:\fP: .P Install a package under a custom alias\. Allows multiple versions of .br a same\-name package side\-by\-side, more convenient import names for .br packages with otherwise long ones, and using git forks replacements .br or forked npm packages as replacements\. Aliasing works only on your .br project and does not rename packages in transitive dependencies\. .br Aliases should follow the naming conventions stated in .br \fBvalidate\-npm\-package\-name\fP\|\. .P Examples: .RS 2 .nf npm install my\-react@npm:react npm install jquery2@npm:jquery@2 npm install jquery3@npm:jquery@3 npm install npa@npm:npm\-package\-arg .fi .RE .IP \(bu 2 \fBnpm install [<@scope>/]@\fP: .P Install the version of the package that is referenced by the specified tag\. .br If the tag does not exist in the registry data for that package, then this .br will fail\. .P Example: .RS 2 .nf npm install sax@latest npm install @myorg/mypackage@latest .fi .RE .IP \(bu 2 \fBnpm install [<@scope>/]@\fP: .P Install the specified version of the package\. This will fail if the .br version has not been published to the registry\. .P Example: .RS 2 .nf npm install sax@0\.1\.1 npm install @myorg/privatepackage@1\.5\.0 .fi .RE .IP \(bu 2 \fBnpm install [<@scope>/]@\fP: .P Install a version of the package matching the specified version range\. .br This will follow the same rules for resolving dependencies described in .br \fBpackage\.json\fP\|\. .P Note that most version ranges must be put in quotes so that your shell .br will treat it as a single argument\. .P Example: .RS 2 .nf npm install sax@">=0\.1\.0 <0\.2\.0" npm install @myorg/privatepackage@"16 \- 17" .fi .RE .IP \(bu 2 \fBnpm install \fP: .P Installs the package from the hosted git provider, cloning it with .br \fBgit\fP\|\. For a full git remote url, only that URL will be attempted\. .RS 2 .nf ://[[:]@][:][:][/][# | #semver:] .fi .RE .P \fB\fP is one of \fBgit\fP, \fBgit+ssh\fP, \fBgit+http\fP, \fBgit+https\fP, or .br \fBgit+file\fP\|\. .P If \fB#\fP is provided, it will be used to clone exactly that .br commit\. If the commit\-ish has the format \fB#semver:\fP, \fB\fP .br can be any valid semver range or exact version, and npm will look for .br any tags or refs matching that range in the remote repository, much as .br it would for a registry dependency\. If neither \fB#\fP or .br \fB#semver:\fP is specified, then the default branch of the .br repository is used\. .P If the repository makes use of submodules, those submodules will be .br cloned as well\. .P If the package being installed contains a \fBprepare\fP script, its .br \fBdependencies\fP and \fBdevDependencies\fP will be installed, and the prepare .br script will be run, before the package is packaged and installed\. .P The following git environment variables are recognized by npm and will .br be added to the environment when running git: .RS 1 .IP \(bu 2 \fBGIT_ASKPASS\fP .IP \(bu 2 \fBGIT_EXEC_PATH\fP .IP \(bu 2 \fBGIT_PROXY_COMMAND\fP .IP \(bu 2 \fBGIT_SSH\fP .IP \(bu 2 \fBGIT_SSH_COMMAND\fP .IP \(bu 2 \fBGIT_SSL_CAINFO\fP .IP \(bu 2 \fBGIT_SSL_NO_VERIFY\fP .RE .P See the git man page for details\. .P Examples: .RS 2 .nf npm install git+ssh://git@github\.com:npm/cli\.git#v1\.0\.27 npm install git+ssh://git@github\.com:npm/cli#pull/273 npm install git+ssh://git@github\.com:npm/cli#semver:^5\.0 npm install git+https://isaacs@github\.com/npm/cli\.git npm install git://github\.com/npm/cli\.git#v1\.0\.27 GIT_SSH_COMMAND='ssh \-i ~/\.ssh/custom_ident' npm install git+ssh://git@github\.com:npm/cli\.git .fi .RE .IP \(bu 2 \fBnpm install /[#]\fP: .IP \(bu 2 \fBnpm install github:/[#]\fP: .P Install the package at \fBhttps://github\.com/githubname/githubrepo\fP by .br attempting to clone it using \fBgit\fP\|\. .P If \fB#\fP is provided, it will be used to clone exactly that .br commit\. If the commit\-ish has the format \fB#semver:\fP, \fB\fP .br can be any valid semver range or exact version, and npm will look for .br any tags or refs matching that range in the remote repository, much as .br it would for a registry dependency\. If neither \fB#\fP or .br \fB#semver:\fP is specified, then the default branch is used\. .P As with regular git dependencies, \fBdependencies\fP and \fBdevDependencies\fP .br will be installed if the package has a \fBprepare\fP script before the .br package is done installing\. .P Examples: .RS 2 .nf npm install mygithubuser/myproject npm install github:mygithubuser/myproject .fi .RE .IP \(bu 2 \fBnpm install gist:[/][#|#semver:]\fP: .P Install the package at \fBhttps://gist\.github\.com/gistID\fP by attempting to .br clone it using \fBgit\fP\|\. The GitHub username associated with the gist is .br optional and will not be saved in \fBpackage\.json\fP\|\. .P As with regular git dependencies, \fBdependencies\fP and \fBdevDependencies\fP will .br be installed if the package has a \fBprepare\fP script before the package is .br done installing\. .P Example: .RS 2 .nf npm install gist:101a11beef .fi .RE .IP \(bu 2 \fBnpm install bitbucket:/[#]\fP: .P Install the package at \fBhttps://bitbucket\.org/bitbucketname/bitbucketrepo\fP .br by attempting to clone it using \fBgit\fP\|\. .P If \fB#\fP is provided, it will be used to clone exactly that .br commit\. If the commit\-ish has the format \fB#semver:\fP, \fB\fP can .br be any valid semver range or exact version, and npm will look for any tags .br or refs matching that range in the remote repository, much as it would for a .br registry dependency\. If neither \fB#\fP or \fB#semver:\fP is .br specified, then \fBmaster\fP is used\. .P As with regular git dependencies, \fBdependencies\fP and \fBdevDependencies\fP will .br be installed if the package has a \fBprepare\fP script before the package is .br done installing\. .P Example: .RS 2 .nf npm install bitbucket:mybitbucketuser/myproject .fi .RE .IP \(bu 2 \fBnpm install gitlab:/[#]\fP: .P Install the package at \fBhttps://gitlab\.com/gitlabname/gitlabrepo\fP .br by attempting to clone it using \fBgit\fP\|\. .P If \fB#\fP is provided, it will be used to clone exactly that .br commit\. If the commit\-ish has the format \fB#semver:\fP, \fB\fP can .br be any valid semver range or exact version, and npm will look for any tags .br or refs matching that range in the remote repository, much as it would for a .br registry dependency\. If neither \fB#\fP or \fB#semver:\fP is .br specified, then \fBmaster\fP is used\. .P As with regular git dependencies, \fBdependencies\fP and \fBdevDependencies\fP will .br be installed if the package has a \fBprepare\fP script before the package is .br done installing\. .P Example: .RS 2 .nf npm install gitlab:mygitlabuser/myproject npm install gitlab:myusr/myproj#semver:^5\.0 .fi .RE .RE .P You may combine multiple arguments and even multiple types of arguments\. .br For example: .RS 2 .nf npm install sax@">=0\.1\.0 <0\.2\.0" bench supervisor .fi .RE .P The \fB\-\-tag\fP argument will apply to all of the specified install targets\. If .br a tag with the given name exists, the tagged version is preferred over .br newer versions\. .P The \fB\-\-dry\-run\fP argument will report in the usual way what the install .br would have done without actually installing anything\. .P The \fB\-\-package\-lock\-only\fP argument will only update the .br \fBpackage\-lock\.json\fP, instead of checking \fBnode_modules\fP and downloading .br dependencies\. .P The \fB\-f\fP or \fB\-\-force\fP argument will force npm to fetch remote resources .br even if a local copy exists on disk\. .RS 2 .nf npm install sax \-\-force .fi .RE .SH Configuration .P See the \fBconfig\fP help doc\. Many of the configuration .br params have some effect on installation, since that's most of what npm .br does\. .P These are some of the most common options related to installation\. .SH Algorithm .P Given a \fBpackage{dep}\fP structure: \fBA{B,C}, B{C}, C{D}\fP, .br the npm install algorithm produces: .RS 2 .nf A +\-\- B +\-\- C +\-\- D .fi .RE .P That is, the dependency from B to C is satisfied by the fact that A already .br caused C to be installed at a higher level\. D is still installed at the top .br level because nothing conflicts with it\. .P For \fBA{B,C}, B{C,D@1}, C{D@2}\fP, this algorithm produces: .RS 2 .nf A +\-\- B +\-\- C `\-\- D@2 +\-\- D@1 .fi .RE .P Because B's D@1 will be installed in the top\-level, C now has to install .br D@2 privately for itself\. This algorithm is deterministic, but different .br trees may be produced if two dependencies are requested for installation in .br a different order\. .P See folders for a more detailed description of .br the specific folder structures that npm creates\. .SH See Also .RS 1 .IP \(bu 2 npm folders .IP \(bu 2 npm update .IP \(bu 2 npm audit .IP \(bu 2 npm fund .IP \(bu 2 npm link .IP \(bu 2 npm rebuild .IP \(bu 2 npm scripts .IP \(bu 2 npm config .IP \(bu 2 npmrc .IP \(bu 2 npm registry .IP \(bu 2 npm dist\-tag .IP \(bu 2 npm uninstall .IP \(bu 2 npm shrinkwrap .IP \(bu 2 package\.json .IP \(bu 2 workspaces .RE