| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 | .TH "NPM\-INSTALL" "1" "August 2021" "" "".SH "NAME"\fBnpm-install\fR \- Install a package.SS Synopsis.P.RS 2.nfnpm install (with no args, in package dir)npm install [<@scope>/]<name>npm install [<@scope>/]<name>@<tag>npm install [<@scope>/]<name>@<version>npm install [<@scope>/]<name>@<version range>npm install <alias>@npm:<name>npm install <git\-host>:<git\-user>/<repo\-name>npm install <git repo url>npm install <tarball file>npm install <tarball url>npm install <folder>aliases: npm i, npm addcommon options: [\-P|\-\-save\-prod|\-D|\-\-save\-dev|\-O|\-\-save\-optional] [\-E|\-\-save\-exact] [\-B|\-\-save\-bundle] [\-\-no\-save] [\-\-dry\-run].fi.RE.SS Description.PThis command installs a package, and any packages that it depends on\. If thepackage has a package\-lock or shrinkwrap file, the installation of dependencieswill be driven by that, with an \fBnpm\-shrinkwrap\.json\fP taking precedence if bothfiles exist\. See npm help package\-lock\.json and npm help \fBshrinkwrap\fP\|\..PA \fBpackage\fP is:.RS 0.IP \(bu 2a) a folder containing a program described by a npm help \fBpackage\.json\fP file.IP \(bu 2b) a gzipped tarball containing (a).IP \(bu 2c) a url that resolves to (b).IP \(bu 2d) a \fB<name>@<version>\fP that is published on the registry (see npm help \fBregistry\fP) with (c).IP \(bu 2e) a \fB<name>@<tag>\fP (see npm help \fBdist\-tag\fP) that points to (d).IP \(bu 2f) a \fB<name>\fP that has a "latest" tag satisfying (e).IP \(bu 2g) a \fB<git remote url>\fP that resolves to (a).RE.PEven if you never publish your package, you can still get a lot ofbenefits of using npm if you just want to write a node program (a), andperhaps if you also want to be able to easily install it elsewhereafter packing it up into a tarball (b)\..RS 0.IP \(bu 2\fBnpm install\fP (in package directory, no arguments):  Install the dependencies in the local node_modules folder\.  In global mode (ie, with \fB\-g\fP or \fB\-\-global\fP appended to the command),  it installs the current package context (ie, the current working  directory) as a global package\.  By default, \fBnpm install\fP will install all modules listed as dependencies  in npm help \fBpackage\.json\fP\|\.  With the \fB\-\-production\fP flag (or when the \fBNODE_ENV\fP environment variable  is set to \fBproduction\fP), npm will not install modules listed in  \fBdevDependencies\fP\|\. To install all modules listed in both \fBdependencies\fP   and \fBdevDependencies\fP when \fBNODE_ENV\fP environment variable is set to \fBproduction\fP,   you can use \fB\-\-production=false\fP\|\..QPNOTE: The \fB\-\-production\fP flag has no particular meaning when adding a  dependency to a project\...IP \(bu 2\fBnpm install <folder>\fP:  Install the package in the directory as a symlink in the current project\.  Its dependencies will be installed before it's linked\. If \fB<folder>\fP sits  inside the root of your project, its dependencies may be hoisted to the  toplevel \fBnode_modules\fP as they would for other types of dependencies\..IP \(bu 2\fBnpm install <tarball file>\fP:  Install a package that is sitting on the filesystem\.  Note: if you just want  to link a dev directory into your npm root, you can do this more easily by  using \fBnpm link\fP\|\.  Tarball requirements:.RS.IP \(bu 2The filename \fImust\fR use \fB\|\.tar\fP, \fB\|\.tar\.gz\fP, or \fB\|\.tgz\fP asthe extension\..IP \(bu 2The package contents should reside in a subfolder inside the tarball (usually it is called \fBpackage/\fP)\. npm strips one directory layer when installing the package (an equivalent of \fBtar x \-\-strip\-components=1\fP is run)\..IP \(bu 2The package must contain a \fBpackage\.json\fP file with \fBname\fP and \fBversion\fP properties\.Example:.P.RS 2.nfnpm install \./package\.tgz.fi.RE.RE.IP \(bu 2\fBnpm install <tarball url>\fP:  Fetch the tarball url, and then install it\.  In order to distinguish between  this and other options, the argument must start with "http://" or "https://"  Example:.P.RS 2.nf    npm install https://github\.com/indexzero/forever/tarball/v0\.5\.6.fi.RE.IP \(bu 2\fBnpm install [<@scope>/]<name>\fP:  Do a \fB<name>@<tag>\fP install, where \fB<tag>\fP is the "tag" config\. (See  npm help \fBconfig\fP\|\. The config's default value is \fBlatest\fP\|\.)  In most cases, this will install the version of the modules tagged as  \fBlatest\fP on the npm registry\.  Example:.P.RS 2.nf    npm install sax.fi.RE.IP \(bu 2\fBnpm install <alias>@npm:<name>\fP:  Install a package under a custom alias\. Allows multiple versions of  a same\-name package side\-by\-side, more convenient import names for  packages with otherwise long ones and using git forks replacements  or forked npm packages as replacements\. Aliasing works only on your  project and does not rename packages in transitive dependencies\.  Aliases should follow the naming conventions stated in  \fBvalidate\-npm\-package\-name\fP \fIhttps://www\.npmjs\.com/package/validate\-npm\-package\-name#naming\-rules\fR\|\.  Examples:.P.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.RE.P.RS 2.nf`npm install` saves any specified packages into `dependencies` by default\.Additionally, you can control where and how they get saved with someadditional flags:* `\-P, \-\-save\-prod`: Package will appear in your `dependencies`\. This is the                     default unless `\-D` or `\-O` are present\.* `\-D, \-\-save\-dev`: Package will appear in your `devDependencies`\.* `\-O, \-\-save\-optional`: Package will appear in your `optionalDependencies`\.* `\-\-no\-save`: Prevents saving to `dependencies`\.When using any of the above options to save dependencies to yourpackage\.json, there are two additional, optional flags:* `\-E, \-\-save\-exact`: Saved dependencies will be configured with an  exact version rather than using npm's default semver range  operator\.* `\-B, \-\-save\-bundle`: Saved dependencies will also be added to your `bundleDependencies` list\.Further, if you have an `npm\-shrinkwrap\.json` or `package\-lock\.json` then itwill be updated as well\.`<scope>` is optional\. The package will be downloaded from the registryassociated with the specified scope\. If no registry is associated withthe given scope the default registry is assumed\. See npm help `scope`\.Note: if you do not include the @\-symbol on your scope name, npm willinterpret this as a GitHub repository instead, see below\. Scopes namesmust also be followed by a slash\.Examples:```bashnpm install saxnpm install githubname/reponamenpm install @myorg/privatepackagenpm install node\-tap \-\-save\-devnpm install dtrace\-provider \-\-save\-optionalnpm install readable\-stream \-\-save\-exactnpm install ansi\-regex \-\-save\-bundle```**Note**: If there is a file or folder named `<name>` in the currentworking directory, then it will try to install that, and only try tofetch the package by name if it is not valid\..fi.RE.RS 0.IP \(bu 2\fBnpm install [<@scope>/]<name>@<tag>\fP:  Install the version of the package that is referenced by the specified tag\.  If the tag does not exist in the registry data for that package, then this  will fail\.  Example:.P.RS 2.nf  npm install sax@latest  npm install @myorg/mypackage@latest.fi.RE.IP \(bu 2\fBnpm install [<@scope>/]<name>@<version>\fP:  Install the specified version of the package\.  This will fail if the  version has not been published to the registry\.  Example:.P.RS 2.nf  npm install sax@0\.1\.1  npm install @myorg/privatepackage@1\.5\.0.fi.RE.IP \(bu 2\fBnpm install [<@scope>/]<name>@<version range>\fP:  Install a version of the package matching the specified version range\.  This  will follow the same rules for resolving dependencies described in npm help \fBpackage\.json\fP\|\.  Note that most version ranges must be put in quotes so that your shell will  treat it as a single argument\.  Example:.P.RS 2.nf  npm install sax@">=0\.1\.0 <0\.2\.0"  npm install @myorg/privatepackage@">=0\.1\.0 <0\.2\.0".fi.RE.IP \(bu 2\fBnpm install <git remote url>\fP:  Installs the package from the hosted git provider, cloning it with \fBgit\fP\|\.  For a full git remote url, only that URL will be attempted\..P.RS 2.nf    <protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit\-ish> | #semver:<semver>].fi.RE  \fB<protocol>\fP is one of \fBgit\fP, \fBgit+ssh\fP, \fBgit+http\fP, \fBgit+https\fP, or  \fBgit+file\fP\|\.  If \fB#<commit\-ish>\fP is provided, it will be used to clone exactly that  commit\. If the commit\-ish has the format \fB#semver:<semver>\fP, \fB<semver>\fP can  be any valid semver range or exact version, and npm will look for any tags  or refs matching that range in the remote repository, much as it would for a  registry dependency\. If neither \fB#<commit\-ish>\fP or \fB#semver:<semver>\fP is  specified, then the default branch of the repository is used\.  If the repository makes use of submodules, those submodules will be cloned  as well\.  If the package being installed contains a \fBprepare\fP script, its  \fBdependencies\fP and \fBdevDependencies\fP will be installed, and the prepare  script will be run, before the package is packaged and installed\.  The following git environment variables are recognized by npm and will be  added to the environment when running git:.RS.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\fPSee the git man page for details\.Examples:.P.RS 2.nfnpm install git+ssh://git@github\.com:npm/cli\.git#v1\.0\.27npm install git+ssh://git@github\.com:npm/cli#semver:^5\.0npm install git+https://isaacs@github\.com/npm/cli\.gitnpm install git://github\.com/npm/cli\.git#v1\.0\.27GIT_SSH_COMMAND='ssh \-i ~/\.ssh/custom_ident' npm install git+ssh://git@github\.com:npm/cli\.git.fi.RE.RE.IP \(bu 2\fBnpm install <githubname>/<githubrepo>[#<commit\-ish>]\fP:.IP \(bu 2\fBnpm install github:<githubname>/<githubrepo>[#<commit\-ish>]\fP:  Install the package at \fBhttps://github\.com/githubname/githubrepo\fP by  attempting to clone it using \fBgit\fP\|\.  If \fB#<commit\-ish>\fP is provided, it will be used to clone exactly that  commit\. If the commit\-ish has the format \fB#semver:<semver>\fP, \fB<semver>\fP can  be any valid semver range or exact version, and npm will look for any tags  or refs matching that range in the remote repository, much as it would for a  registry dependency\. If neither \fB#<commit\-ish>\fP or \fB#semver:<semver>\fP is  specified, then \fBmaster\fP is used\.  As with regular git dependencies, \fBdependencies\fP and \fBdevDependencies\fP will  be installed if the package has a \fBprepare\fP script, before the package is  done installing\.  Examples:.P.RS 2.nf  npm install mygithubuser/myproject  npm install github:mygithubuser/myproject.fi.RE.IP \(bu 2\fBnpm install gist:[<githubname>/]<gistID>[#<commit\-ish>|#semver:<semver>]\fP:  Install the package at \fBhttps://gist\.github\.com/gistID\fP by attempting to  clone it using \fBgit\fP\|\. The GitHub username associated with the gist is  optional and will not be saved in \fBpackage\.json\fP\|\.  As with regular git dependencies, \fBdependencies\fP and \fBdevDependencies\fP will  be installed if the package has a \fBprepare\fP script, before the package is  done installing\.  Example:.P.RS 2.nf  npm install gist:101a11beef.fi.RE.IP \(bu 2\fBnpm install bitbucket:<bitbucketname>/<bitbucketrepo>[#<commit\-ish>]\fP:  Install the package at \fBhttps://bitbucket\.org/bitbucketname/bitbucketrepo\fP  by attempting to clone it using \fBgit\fP\|\.  If \fB#<commit\-ish>\fP is provided, it will be used to clone exactly that  commit\. If the commit\-ish has the format \fB#semver:<semver>\fP, \fB<semver>\fP can  be any valid semver range or exact version, and npm will look for any tags  or refs matching that range in the remote repository, much as it would for a  registry dependency\. If neither \fB#<commit\-ish>\fP or \fB#semver:<semver>\fP is  specified, then \fBmaster\fP is used\.  As with regular git dependencies, \fBdependencies\fP and \fBdevDependencies\fP will  be installed if the package has a \fBprepare\fP script, before the package is  done installing\.  Example:.P.RS 2.nf  npm install bitbucket:mybitbucketuser/myproject.fi.RE.IP \(bu 2\fBnpm install gitlab:<gitlabname>/<gitlabrepo>[#<commit\-ish>]\fP:  Install the package at \fBhttps://gitlab\.com/gitlabname/gitlabrepo\fP  by attempting to clone it using \fBgit\fP\|\.  If \fB#<commit\-ish>\fP is provided, it will be used to clone exactly that  commit\. If the commit\-ish has the format \fB#semver:<semver>\fP, \fB<semver>\fP can  be any valid semver range or exact version, and npm will look for any tags  or refs matching that range in the remote repository, much as it would for a  registry dependency\. If neither \fB#<commit\-ish>\fP or \fB#semver:<semver>\fP is  specified, then \fBmaster\fP is used\.  As with regular git dependencies, \fBdependencies\fP and \fBdevDependencies\fP will  be installed if the package has a \fBprepare\fP script, before the package is  done installing\.  Example:.P.RS 2.nf  npm install gitlab:mygitlabuser/myproject  npm install gitlab:myusr/myproj#semver:^5\.0.fi.RE.RE.PYou may combine multiple arguments, and even multiple types of arguments\.For example:.P.RS 2.nfnpm install sax@">=0\.1\.0 <0\.2\.0" bench supervisor.fi.RE.PThe \fB\-\-tag\fP argument will apply to all of the specified install targets\. If atag with the given name exists, the tagged version is preferred over newerversions\..PThe \fB\-\-dry\-run\fP argument will report in the usual way what the install wouldhave done without actually installing anything\..PThe \fB\-\-package\-lock\-only\fP argument will only update the \fBpackage\-lock\.json\fP,instead of checking \fBnode_modules\fP and downloading dependencies\..PThe \fB\-f\fP or \fB\-\-force\fP argument will force npm to fetch remote resources even if alocal copy exists on disk\..P.RS 2.nfnpm install sax \-\-force.fi.RE.PThe \fB\-\-no\-fund\fP argument will hide the message displayed at the end of eachinstall that acknowledges the number of dependencies looking for funding\.See \fBnpm\-fund(1)\fP.PThe \fB\-g\fP or \fB\-\-global\fP argument will cause npm to install the package globallyrather than locally\.  See npm help folders\..PThe \fB\-\-global\-style\fP argument will cause npm to install the package intoyour local \fBnode_modules\fP folder with the same layout it uses with theglobal \fBnode_modules\fP folder\. Only your direct dependencies will show in\fBnode_modules\fP and everything they depend on will be flattened in their\fBnode_modules\fP folders\. This obviously will eliminate some deduping\..PThe \fB\-\-ignore\-scripts\fP argument will cause npm to not execute anyscripts defined in the package\.json\. See npm help \fBscripts\fP\|\..PThe \fB\-\-legacy\-bundling\fP argument will cause npm to install the package suchthat versions of npm prior to 1\.4, such as the one included with node 0\.8,can install the package\. This eliminates all automatic deduping\..PThe \fB\-\-link\fP argument will cause npm to link global installs into thelocal space in some cases\..PThe \fB\-\-no\-bin\-links\fP argument will prevent npm from creating symlinks forany binaries the package might contain\..PThe \fB\-\-no\-optional\fP argument will prevent optional dependencies frombeing installed\..PThe \fB\-\-no\-shrinkwrap\fP argument, which will ignore an availablepackage lock or shrinkwrap file and use the package\.json instead\..PThe \fB\-\-no\-package\-lock\fP argument will prevent npm from creating a\fBpackage\-lock\.json\fP file\.  When running with package\-lock's disabled npmwill not automatically prune your node modules when installing\..PThe \fB\-\-nodedir=/path/to/node/source\fP argument will allow npm to find thenode source code so that npm can compile native modules\..PThe \fB\-\-only={prod[uction]|dev[elopment]}\fP argument will cause either only\fBdevDependencies\fP or only non\-\fBdevDependencies\fP to be installed regardless of the \fBNODE_ENV\fP\|\..PThe \fB\-\-no\-audit\fP argument can be used to disable sending of audit reports tothe configured registries\.  See \fBnpm\-audit\fP \fInpm\-audit\fR for details on what is sent\..PSee npm help \fBconfig\fP\|\.  Many of the configuration params have someeffect on installation, since that's most of what npm does\..SS Algorithm.PTo install a package, npm uses the following algorithm:.P.RS 2.nfload the existing node_modules tree from diskclone the treefetch the package\.json and assorted metadata and add it to the clonewalk the clone and add any missing dependencies  dependencies will be added as close to the top as is possible  without breaking any other modulescompare the original tree with the cloned tree and make a list ofactions to take to convert one to the otherexecute all of the actions, deepest first  kinds of actions are install, update, remove and move.fi.RE.PFor this \fBpackage{dep}\fP structure: \fBA{B,C}, B{C}, C{D}\fP,this algorithm produces:.P.RS 2.nfA+\-\- B+\-\- C+\-\- D.fi.RE.PThat is, the dependency from B to C is satisfied by the fact that Aalready caused C to be installed at a higher level\. D is still installedat the top level because nothing conflicts with it\..PFor \fBA{B,C}, B{C,D@1}, C{D@2}\fP, this algorithm produces:.P.RS 2.nfA+\-\- B+\-\- C   `\-\- D@2+\-\- D@1.fi.RE.PBecause B's D@1 will be installed in the top level, C now has to install D@2privately for itself\. This algorithm is deterministic, but different trees maybe produced if two dependencies are requested for installation in a differentorder\..PSee npm help folders for a more detailed description of the specific folder structures that npm creates\..SS Limitations of npm's Install Algorithm.Pnpm will refuse to install any package with an identical name to thecurrent package\. This can be overridden with the \fB\-\-force\fP flag, but inmost cases can simply be addressed by changing the local package name\..PThere are some very rare and pathological edge\-cases where a cycle cancause npm to try to install a never\-ending tree of packages\.  Here isthe simplest case:.P.RS 2.nfA \-> B \-> A' \-> B' \-> A \-> B \-> A' \-> B' \-> A \-> \.\.\..fi.RE.Pwhere \fBA\fP is some version of a package, and \fBA'\fP is a different versionof the same package\.  Because \fBB\fP depends on a different version of \fBA\fPthan the one that is already in the tree, it must install a separatecopy\.  The same is true of \fBA'\fP, which must install \fBB'\fP\|\.  Because \fBB'\fPdepends on the original version of \fBA\fP, which has been overridden, thecycle falls into infinite regress\..PTo avoid this situation, npm flat\-out refuses to install any\fBname@version\fP that is already present anywhere in the tree of packagefolder ancestors\.  A more correct, but more complex, solution would beto symlink the existing version into the new location\.  If this everaffects a real use\-case, it will be investigated\..SS See Also.RS 0.IP \(bu 2npm help folders.IP \(bu 2npm help update.IP \(bu 2npm help audit.IP \(bu 2npm help fund.IP \(bu 2npm help link.IP \(bu 2npm help rebuild.IP \(bu 2npm help scripts.IP \(bu 2npm help build.IP \(bu 2npm help config.IP \(bu 2npm help npmrc.IP \(bu 2npm help registry.IP \(bu 2npm help dist\-tag.IP \(bu 2npm help uninstall.IP \(bu 2npm help shrinkwrap.IP \(bu 2npm help package\.json.RE
 |