npm-install.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. <html><head>
  2. <title>npm-install</title>
  3. <style>
  4. body {
  5. background-color: #ffffff;
  6. color: #24292e;
  7. margin: 0;
  8. line-height: 1.5;
  9. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  10. }
  11. #rainbar {
  12. height: 10px;
  13. background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
  14. }
  15. a {
  16. text-decoration: none;
  17. color: #0366d6;
  18. }
  19. a:hover {
  20. text-decoration: underline;
  21. }
  22. pre {
  23. margin: 1em 0px;
  24. padding: 1em;
  25. border: solid 1px #e1e4e8;
  26. border-radius: 6px;
  27. display: block;
  28. overflow: auto;
  29. white-space: pre;
  30. background-color: #f6f8fa;
  31. color: #393a34;
  32. }
  33. code {
  34. font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
  35. font-size: 85%;
  36. padding: 0.2em 0.4em;
  37. background-color: #f6f8fa;
  38. color: #393a34;
  39. }
  40. pre > code {
  41. padding: 0;
  42. background-color: inherit;
  43. color: inherit;
  44. }
  45. h1, h2, h3 {
  46. font-weight: 600;
  47. }
  48. #logobar {
  49. background-color: #333333;
  50. margin: 0 auto;
  51. padding: 1em 4em;
  52. }
  53. #logobar .logo {
  54. float: left;
  55. }
  56. #logobar .title {
  57. font-weight: 600;
  58. color: #dddddd;
  59. float: left;
  60. margin: 5px 0 0 1em;
  61. }
  62. #logobar:after {
  63. content: "";
  64. display: block;
  65. clear: both;
  66. }
  67. #content {
  68. margin: 0 auto;
  69. padding: 0 4em;
  70. }
  71. #table_of_contents > h2 {
  72. font-size: 1.17em;
  73. }
  74. #table_of_contents ul:first-child {
  75. border: solid 1px #e1e4e8;
  76. border-radius: 6px;
  77. padding: 1em;
  78. background-color: #f6f8fa;
  79. color: #393a34;
  80. }
  81. #table_of_contents ul {
  82. list-style-type: none;
  83. padding-left: 1.5em;
  84. }
  85. #table_of_contents li {
  86. font-size: 0.9em;
  87. }
  88. #table_of_contents li a {
  89. color: #000000;
  90. }
  91. header.title {
  92. border-bottom: solid 1px #e1e4e8;
  93. }
  94. header.title > h1 {
  95. margin-bottom: 0.25em;
  96. }
  97. header.title > .description {
  98. display: block;
  99. margin-bottom: 0.5em;
  100. line-height: 1;
  101. }
  102. footer#edit {
  103. border-top: solid 1px #e1e4e8;
  104. margin: 3em 0 4em 0;
  105. padding-top: 2em;
  106. }
  107. </style>
  108. </head>
  109. <body>
  110. <div id="banner">
  111. <div id="rainbar"></div>
  112. <div id="logobar">
  113. <svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
  114. <polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
  115. <polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
  116. </svg>
  117. <div class="title">
  118. npm command-line interface
  119. </div>
  120. </div>
  121. </div>
  122. <section id="content">
  123. <header class="title">
  124. <h1 id="npm-install">npm-install</h1>
  125. <span class="description">Install a package</span>
  126. </header>
  127. <section id="table_of_contents">
  128. <h2 id="table-of-contents">Table of contents</h2>
  129. <div id="_table_of_contents"><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#description">Description</a></li><li><a href="#configuration">Configuration</a></li><ul><li><a href="#save"><code>save</code></a></li><li><a href="#save-exact"><code>save-exact</code></a></li><li><a href="#global"><code>global</code></a></li><li><a href="#global-style"><code>global-style</code></a></li><li><a href="#legacy-bundling"><code>legacy-bundling</code></a></li><li><a href="#strict-peer-deps"><code>strict-peer-deps</code></a></li><li><a href="#package-lock"><code>package-lock</code></a></li><li><a href="#omit"><code>omit</code></a></li><li><a href="#ignore-scripts"><code>ignore-scripts</code></a></li><li><a href="#audit"><code>audit</code></a></li><li><a href="#bin-links"><code>bin-links</code></a></li><li><a href="#fund"><code>fund</code></a></li><li><a href="#dry-run"><code>dry-run</code></a></li><li><a href="#workspace"><code>workspace</code></a></li><li><a href="#workspaces"><code>workspaces</code></a></li><li><a href="#include-workspace-root"><code>include-workspace-root</code></a></li></ul><li><a href="#algorithm">Algorithm</a></li><li><a href="#see-also">See Also</a></li></ul></div>
  130. </section>
  131. <div id="_content"><h3 id="synopsis">Synopsis</h3>
  132. <pre lang="bash"><code>npm install (with no args, in package dir)
  133. npm install [&lt;@scope&gt;/]&lt;name&gt;
  134. npm install [&lt;@scope&gt;/]&lt;name&gt;@&lt;tag&gt;
  135. npm install [&lt;@scope&gt;/]&lt;name&gt;@&lt;version&gt;
  136. npm install [&lt;@scope&gt;/]&lt;name&gt;@&lt;version range&gt;
  137. npm install &lt;alias&gt;@npm:&lt;name&gt;
  138. npm install &lt;git-host&gt;:&lt;git-user&gt;/&lt;repo-name&gt;
  139. npm install &lt;git repo url&gt;
  140. npm install &lt;tarball file&gt;
  141. npm install &lt;tarball url&gt;
  142. npm install &lt;folder&gt;
  143. aliases: npm i, npm add
  144. common options: [-P|--save-prod|-D|--save-dev|-O|--save-optional|--save-peer] [-E|--save-exact] [-B|--save-bundle] [--no-save] [--dry-run]
  145. </code></pre>
  146. <h3 id="description">Description</h3>
  147. <p>This command installs a package and any packages that it depends on. If the
  148. package has a package-lock, or an npm shrinkwrap file, or a yarn lock file,
  149. the installation of dependencies will be driven by that, respecting the
  150. following order of precedence:</p>
  151. <ul>
  152. <li><code>npm-shrinkwrap.json</code></li>
  153. <li><code>package-lock.json</code></li>
  154. <li><code>yarn.lock</code></li>
  155. </ul>
  156. <p>See <a href="../configuring-npm/package-lock-json.html">package-lock.json</a> and
  157. <a href="../commands/npm-shrinkwrap.html"><code>npm shrinkwrap</code></a>.</p>
  158. <p>A <code>package</code> is:</p>
  159. <ul>
  160. <li>a) a folder containing a program described by a
  161. <a href="../configuring-npm/package-json.html"><code>package.json</code></a> file</li>
  162. <li>b) a gzipped tarball containing (a)</li>
  163. <li>c) a url that resolves to (b)</li>
  164. <li>d) a <code>&lt;name&gt;@&lt;version&gt;</code> that is published on the registry (see
  165. <a href="../using-npm/registry.html"><code>registry</code></a>) with (c)</li>
  166. <li>e) a <code>&lt;name&gt;@&lt;tag&gt;</code> (see <a href="../commands/npm-dist-tag.html"><code>npm dist-tag</code></a>) that
  167. points to (d)</li>
  168. <li>f) a <code>&lt;name&gt;</code> that has a “latest” tag satisfying (e)</li>
  169. <li>g) a <code>&lt;git remote url&gt;</code> that resolves to (a)</li>
  170. </ul>
  171. <p>Even if you never publish your package, you can still get a lot of benefits
  172. of using npm if you just want to write a node program (a), and perhaps if
  173. you also want to be able to easily install it elsewhere after packing it up
  174. into a tarball (b).</p>
  175. <ul>
  176. <li>
  177. <p><code>npm install</code> (in a package directory, no arguments):</p>
  178. <p>Install the dependencies in the local <code>node_modules</code> folder.</p>
  179. <p>In global mode (ie, with <code>-g</code> or <code>--global</code> appended to the command),
  180. it installs the current package context (ie, the current working
  181. directory) as a global package.</p>
  182. <p>By default, <code>npm install</code> will install all modules listed as
  183. dependencies in <a href="../configuring-npm/package-json.html"><code>package.json</code></a>.</p>
  184. <p>With the <code>--production</code> flag (or when the <code>NODE_ENV</code> environment
  185. variable is set to <code>production</code>), npm will not install modules listed
  186. in <code>devDependencies</code>. To install all modules listed in both
  187. <code>dependencies</code> and <code>devDependencies</code> when <code>NODE_ENV</code> environment
  188. variable is set to <code>production</code>, you can use <code>--production=false</code>.</p>
  189. <blockquote>
  190. <p>NOTE: The <code>--production</code> flag has no particular meaning when adding a
  191. dependency to a project.</p>
  192. </blockquote>
  193. </li>
  194. <li>
  195. <p><code>npm install &lt;folder&gt;</code>:</p>
  196. <p>Install the package in the directory as a symlink in the current
  197. project. Its dependencies will be installed before it’s linked. If
  198. <code>&lt;folder&gt;</code> sits inside the root of your project, its dependencies may
  199. be hoisted to the top-level <code>node_modules</code> as they would for other
  200. types of dependencies.</p>
  201. </li>
  202. <li>
  203. <p><code>npm install &lt;tarball file&gt;</code>:</p>
  204. <p>Install a package that is sitting on the filesystem. Note: if you just
  205. want to link a dev directory into your npm root, you can do this more
  206. easily by using <a href="../commands/npm-link.html"><code>npm link</code></a>.</p>
  207. <p>Tarball requirements:</p>
  208. <ul>
  209. <li>The filename <em>must</em> use <code>.tar</code>, <code>.tar.gz</code>, or <code>.tgz</code> as the
  210. extension.</li>
  211. <li>The package contents should reside in a subfolder inside the tarball
  212. (usually it is called <code>package/</code>). npm strips one directory layer
  213. when installing the package (an equivalent of <code>tar x --strip-components=1</code> is run).</li>
  214. <li>The package must contain a <code>package.json</code> file with <code>name</code> and
  215. <code>version</code> properties.</li>
  216. </ul>
  217. <p>Example:</p>
  218. <pre lang="bash"><code>npm install ./package.tgz
  219. </code></pre>
  220. </li>
  221. <li>
  222. <p><code>npm install &lt;tarball url&gt;</code>:</p>
  223. <p>Fetch the tarball url, and then install it. In order to distinguish between
  224. this and other options, the argument must start with “http://” or “https://”</p>
  225. <p>Example:</p>
  226. <pre lang="bash"><code>npm install https://github.com/indexzero/forever/tarball/v0.5.6
  227. </code></pre>
  228. </li>
  229. <li>
  230. <p><code>npm install [&lt;@scope&gt;/]&lt;name&gt;</code>:</p>
  231. <p>Do a <code>&lt;name&gt;@&lt;tag&gt;</code> install, where <code>&lt;tag&gt;</code> is the “tag” config. (See
  232. <a href="../using-npm/config.html"><code>config</code></a>. The config’s default value is <code>latest</code>.)</p>
  233. <p>In most cases, this will install the version of the modules tagged as
  234. <code>latest</code> on the npm registry.</p>
  235. <p>Example:</p>
  236. <pre lang="bash"><code>npm install sax
  237. </code></pre>
  238. <p><code>npm install</code> saves any specified packages into <code>dependencies</code> by default.
  239. Additionally, you can control where and how they get saved with some
  240. additional flags:</p>
  241. <ul>
  242. <li>
  243. <p><code>-P, --save-prod</code>: Package will appear in your <code>dependencies</code>. This
  244. is the default unless <code>-D</code> or <code>-O</code> are present.</p>
  245. </li>
  246. <li>
  247. <p><code>-D, --save-dev</code>: Package will appear in your <code>devDependencies</code>.</p>
  248. </li>
  249. <li>
  250. <p><code>-O, --save-optional</code>: Package will appear in your
  251. <code>optionalDependencies</code>.</p>
  252. </li>
  253. <li>
  254. <p><code>--no-save</code>: Prevents saving to <code>dependencies</code>.</p>
  255. </li>
  256. </ul>
  257. <p>When using any of the above options to save dependencies to your
  258. package.json, there are two additional, optional flags:</p>
  259. <ul>
  260. <li>
  261. <p><code>-E, --save-exact</code>: Saved dependencies will be configured with an
  262. exact version rather than using npm’s default semver range operator.</p>
  263. </li>
  264. <li>
  265. <p><code>-B, --save-bundle</code>: Saved dependencies will also be added to your
  266. <code>bundleDependencies</code> list.</p>
  267. </li>
  268. </ul>
  269. <p>Further, if you have an <code>npm-shrinkwrap.json</code> or <code>package-lock.json</code>
  270. then it will be updated as well.</p>
  271. <p><code>&lt;scope&gt;</code> is optional. The package will be downloaded from the registry
  272. associated with the specified scope. If no registry is associated with
  273. the given scope the default registry is assumed. See
  274. <a href="../using-npm/scope.html"><code>scope</code></a>.</p>
  275. <p>Note: if you do not include the @-symbol on your scope name, npm will
  276. interpret this as a GitHub repository instead, see below. Scopes names
  277. must also be followed by a slash.</p>
  278. <p>Examples:</p>
  279. <pre lang="bash"><code>npm install sax
  280. npm install githubname/reponame
  281. npm install @myorg/privatepackage
  282. npm install node-tap --save-dev
  283. npm install dtrace-provider --save-optional
  284. npm install readable-stream --save-exact
  285. npm install ansi-regex --save-bundle
  286. </code></pre>
  287. <p><strong>Note</strong>: If there is a file or folder named <code>&lt;name&gt;</code> in the current
  288. working directory, then it will try to install that, and only try to
  289. fetch the package by name if it is not valid.</p>
  290. </li>
  291. <li>
  292. <p><code>npm install &lt;alias&gt;@npm:&lt;name&gt;</code>:</p>
  293. <p>Install a package under a custom alias. Allows multiple versions of
  294. a same-name package side-by-side, more convenient import names for
  295. packages with otherwise long ones, and using git forks replacements
  296. or forked npm packages as replacements. Aliasing works only on your
  297. project and does not rename packages in transitive dependencies.
  298. Aliases should follow the naming conventions stated in
  299. <a href="https://www.npmjs.com/package/validate-npm-package-name#naming-rules"><code>validate-npm-package-name</code></a>.</p>
  300. <p>Examples:</p>
  301. <pre lang="bash"><code>npm install my-react@npm:react
  302. npm install jquery2@npm:jquery@2
  303. npm install jquery3@npm:jquery@3
  304. npm install npa@npm:npm-package-arg
  305. </code></pre>
  306. </li>
  307. <li>
  308. <p><code>npm install [&lt;@scope&gt;/]&lt;name&gt;@&lt;tag&gt;</code>:</p>
  309. <p>Install the version of the package that is referenced by the specified tag.
  310. If the tag does not exist in the registry data for that package, then this
  311. will fail.</p>
  312. <p>Example:</p>
  313. <pre lang="bash"><code>npm install sax@latest
  314. npm install @myorg/mypackage@latest
  315. </code></pre>
  316. </li>
  317. <li>
  318. <p><code>npm install [&lt;@scope&gt;/]&lt;name&gt;@&lt;version&gt;</code>:</p>
  319. <p>Install the specified version of the package. This will fail if the
  320. version has not been published to the registry.</p>
  321. <p>Example:</p>
  322. <pre lang="bash"><code>npm install sax@0.1.1
  323. npm install @myorg/privatepackage@1.5.0
  324. </code></pre>
  325. </li>
  326. <li>
  327. <p><code>npm install [&lt;@scope&gt;/]&lt;name&gt;@&lt;version range&gt;</code>:</p>
  328. <p>Install a version of the package matching the specified version range.
  329. This will follow the same rules for resolving dependencies described in
  330. <a href="../configuring-npm/package-json.html"><code>package.json</code></a>.</p>
  331. <p>Note that most version ranges must be put in quotes so that your shell
  332. will treat it as a single argument.</p>
  333. <p>Example:</p>
  334. <pre lang="bash"><code>npm install sax@"&gt;=0.1.0 &lt;0.2.0"
  335. npm install @myorg/privatepackage@"16 - 17"
  336. </code></pre>
  337. </li>
  338. <li>
  339. <p><code>npm install &lt;git remote url&gt;</code>:</p>
  340. <p>Installs the package from the hosted git provider, cloning it with
  341. <code>git</code>. For a full git remote url, only that URL will be attempted.</p>
  342. <pre lang="bash"><code>&lt;protocol&gt;://[&lt;user&gt;[:&lt;password&gt;]@]&lt;hostname&gt;[:&lt;port&gt;][:][/]&lt;path&gt;[#&lt;commit-ish&gt; | #semver:&lt;semver&gt;]
  343. </code></pre>
  344. <p><code>&lt;protocol&gt;</code> is one of <code>git</code>, <code>git+ssh</code>, <code>git+http</code>, <code>git+https</code>, or
  345. <code>git+file</code>.</p>
  346. <p>If <code>#&lt;commit-ish&gt;</code> is provided, it will be used to clone exactly that
  347. commit. If the commit-ish has the format <code>#semver:&lt;semver&gt;</code>, <code>&lt;semver&gt;</code>
  348. can be any valid semver range or exact version, and npm will look for
  349. any tags or refs matching that range in the remote repository, much as
  350. it would for a registry dependency. If neither <code>#&lt;commit-ish&gt;</code> or
  351. <code>#semver:&lt;semver&gt;</code> is specified, then the default branch of the
  352. repository is used.</p>
  353. <p>If the repository makes use of submodules, those submodules will be
  354. cloned as well.</p>
  355. <p>If the package being installed contains a <code>prepare</code> script, its
  356. <code>dependencies</code> and <code>devDependencies</code> will be installed, and the prepare
  357. script will be run, before the package is packaged and installed.</p>
  358. <p>The following git environment variables are recognized by npm and will
  359. be added to the environment when running git:</p>
  360. <ul>
  361. <li><code>GIT_ASKPASS</code></li>
  362. <li><code>GIT_EXEC_PATH</code></li>
  363. <li><code>GIT_PROXY_COMMAND</code></li>
  364. <li><code>GIT_SSH</code></li>
  365. <li><code>GIT_SSH_COMMAND</code></li>
  366. <li><code>GIT_SSL_CAINFO</code></li>
  367. <li><code>GIT_SSL_NO_VERIFY</code></li>
  368. </ul>
  369. <p>See the git man page for details.</p>
  370. <p>Examples:</p>
  371. <pre lang="bash"><code>npm install git+ssh://git@github.com:npm/cli.git#v1.0.27
  372. npm install git+ssh://git@github.com:npm/cli#pull/273
  373. npm install git+ssh://git@github.com:npm/cli#semver:^5.0
  374. npm install git+https://isaacs@github.com/npm/cli.git
  375. npm install git://github.com/npm/cli.git#v1.0.27
  376. GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git@github.com:npm/cli.git
  377. </code></pre>
  378. </li>
  379. <li>
  380. <p><code>npm install &lt;githubname&gt;/&lt;githubrepo&gt;[#&lt;commit-ish&gt;]</code>:</p>
  381. </li>
  382. <li>
  383. <p><code>npm install github:&lt;githubname&gt;/&lt;githubrepo&gt;[#&lt;commit-ish&gt;]</code>:</p>
  384. <p>Install the package at <code>https://github.com/githubname/githubrepo</code> by
  385. attempting to clone it using <code>git</code>.</p>
  386. <p>If <code>#&lt;commit-ish&gt;</code> is provided, it will be used to clone exactly that
  387. commit. If the commit-ish has the format <code>#semver:&lt;semver&gt;</code>, <code>&lt;semver&gt;</code>
  388. can be any valid semver range or exact version, and npm will look for
  389. any tags or refs matching that range in the remote repository, much as
  390. it would for a registry dependency. If neither <code>#&lt;commit-ish&gt;</code> or
  391. <code>#semver:&lt;semver&gt;</code> is specified, then <code>master</code> is used.</p>
  392. <p>As with regular git dependencies, <code>dependencies</code> and <code>devDependencies</code>
  393. will be installed if the package has a <code>prepare</code> script before the
  394. package is done installing.</p>
  395. <p>Examples:</p>
  396. <pre lang="bash"><code>npm install mygithubuser/myproject
  397. npm install github:mygithubuser/myproject
  398. </code></pre>
  399. </li>
  400. <li>
  401. <p><code>npm install gist:[&lt;githubname&gt;/]&lt;gistID&gt;[#&lt;commit-ish&gt;|#semver:&lt;semver&gt;]</code>:</p>
  402. <p>Install the package at <code>https://gist.github.com/gistID</code> by attempting to
  403. clone it using <code>git</code>. The GitHub username associated with the gist is
  404. optional and will not be saved in <code>package.json</code>.</p>
  405. <p>As with regular git dependencies, <code>dependencies</code> and <code>devDependencies</code> will
  406. be installed if the package has a <code>prepare</code> script before the package is
  407. done installing.</p>
  408. <p>Example:</p>
  409. <pre lang="bash"><code>npm install gist:101a11beef
  410. </code></pre>
  411. </li>
  412. <li>
  413. <p><code>npm install bitbucket:&lt;bitbucketname&gt;/&lt;bitbucketrepo&gt;[#&lt;commit-ish&gt;]</code>:</p>
  414. <p>Install the package at <code>https://bitbucket.org/bitbucketname/bitbucketrepo</code>
  415. by attempting to clone it using <code>git</code>.</p>
  416. <p>If <code>#&lt;commit-ish&gt;</code> is provided, it will be used to clone exactly that
  417. commit. If the commit-ish has the format <code>#semver:&lt;semver&gt;</code>, <code>&lt;semver&gt;</code> can
  418. be any valid semver range or exact version, and npm will look for any tags
  419. or refs matching that range in the remote repository, much as it would for a
  420. registry dependency. If neither <code>#&lt;commit-ish&gt;</code> or <code>#semver:&lt;semver&gt;</code> is
  421. specified, then <code>master</code> is used.</p>
  422. <p>As with regular git dependencies, <code>dependencies</code> and <code>devDependencies</code> will
  423. be installed if the package has a <code>prepare</code> script before the package is
  424. done installing.</p>
  425. <p>Example:</p>
  426. <pre lang="bash"><code>npm install bitbucket:mybitbucketuser/myproject
  427. </code></pre>
  428. </li>
  429. <li>
  430. <p><code>npm install gitlab:&lt;gitlabname&gt;/&lt;gitlabrepo&gt;[#&lt;commit-ish&gt;]</code>:</p>
  431. <p>Install the package at <code>https://gitlab.com/gitlabname/gitlabrepo</code>
  432. by attempting to clone it using <code>git</code>.</p>
  433. <p>If <code>#&lt;commit-ish&gt;</code> is provided, it will be used to clone exactly that
  434. commit. If the commit-ish has the format <code>#semver:&lt;semver&gt;</code>, <code>&lt;semver&gt;</code> can
  435. be any valid semver range or exact version, and npm will look for any tags
  436. or refs matching that range in the remote repository, much as it would for a
  437. registry dependency. If neither <code>#&lt;commit-ish&gt;</code> or <code>#semver:&lt;semver&gt;</code> is
  438. specified, then <code>master</code> is used.</p>
  439. <p>As with regular git dependencies, <code>dependencies</code> and <code>devDependencies</code> will
  440. be installed if the package has a <code>prepare</code> script before the package is
  441. done installing.</p>
  442. <p>Example:</p>
  443. <pre lang="bash"><code>npm install gitlab:mygitlabuser/myproject
  444. npm install gitlab:myusr/myproj#semver:^5.0
  445. </code></pre>
  446. </li>
  447. </ul>
  448. <p>You may combine multiple arguments and even multiple types of arguments.
  449. For example:</p>
  450. <pre lang="bash"><code>npm install sax@"&gt;=0.1.0 &lt;0.2.0" bench supervisor
  451. </code></pre>
  452. <p>The <code>--tag</code> argument will apply to all of the specified install targets. If
  453. a tag with the given name exists, the tagged version is preferred over
  454. newer versions.</p>
  455. <p>The <code>--dry-run</code> argument will report in the usual way what the install
  456. would have done without actually installing anything.</p>
  457. <p>The <code>--package-lock-only</code> argument will only update the
  458. <code>package-lock.json</code>, instead of checking <code>node_modules</code> and downloading
  459. dependencies.</p>
  460. <p>The <code>-f</code> or <code>--force</code> argument will force npm to fetch remote resources
  461. even if a local copy exists on disk.</p>
  462. <pre lang="bash"><code>npm install sax --force
  463. </code></pre>
  464. <h3 id="configuration">Configuration</h3>
  465. <p>See the <a href="../using-npm/config.html"><code>config</code></a> help doc. Many of the configuration
  466. params have some effect on installation, since that’s most of what npm
  467. does.</p>
  468. <p>These are some of the most common options related to installation.</p>
  469. <!-- raw HTML omitted -->
  470. <!-- raw HTML omitted -->
  471. <!-- raw HTML omitted -->
  472. <h4 id="save"><code>save</code></h4>
  473. <ul>
  474. <li>Default: true</li>
  475. <li>Type: Boolean</li>
  476. </ul>
  477. <p>Save installed packages to a package.json file as dependencies.</p>
  478. <p>When used with the <code>npm rm</code> command, removes the dependency from
  479. package.json.</p>
  480. <!-- raw HTML omitted -->
  481. <!-- raw HTML omitted -->
  482. <h4 id="save-exact"><code>save-exact</code></h4>
  483. <ul>
  484. <li>Default: false</li>
  485. <li>Type: Boolean</li>
  486. </ul>
  487. <p>Dependencies saved to package.json will be configured with an exact version
  488. rather than using npm’s default semver range operator.</p>
  489. <!-- raw HTML omitted -->
  490. <!-- raw HTML omitted -->
  491. <h4 id="global"><code>global</code></h4>
  492. <ul>
  493. <li>Default: false</li>
  494. <li>Type: Boolean</li>
  495. </ul>
  496. <p>Operates in “global” mode, so that packages are installed into the <code>prefix</code>
  497. folder instead of the current working directory. See
  498. <a href="../configuring-npm/folders.html">folders</a> for more on the differences in behavior.</p>
  499. <ul>
  500. <li>packages are installed into the <code>{prefix}/lib/node_modules</code> folder, instead
  501. of the current working directory.</li>
  502. <li>bin files are linked to <code>{prefix}/bin</code></li>
  503. <li>man pages are linked to <code>{prefix}/share/man</code></li>
  504. </ul>
  505. <!-- raw HTML omitted -->
  506. <!-- raw HTML omitted -->
  507. <h4 id="global-style"><code>global-style</code></h4>
  508. <ul>
  509. <li>Default: false</li>
  510. <li>Type: Boolean</li>
  511. </ul>
  512. <p>Causes npm to install the package into your local <code>node_modules</code> folder with
  513. the same layout it uses with the global <code>node_modules</code> folder. Only your
  514. direct dependencies will show in <code>node_modules</code> and everything they depend
  515. on will be flattened in their <code>node_modules</code> folders. This obviously will
  516. eliminate some deduping. If used with <code>legacy-bundling</code>, <code>legacy-bundling</code>
  517. will be preferred.</p>
  518. <!-- raw HTML omitted -->
  519. <!-- raw HTML omitted -->
  520. <h4 id="legacy-bundling"><code>legacy-bundling</code></h4>
  521. <ul>
  522. <li>Default: false</li>
  523. <li>Type: Boolean</li>
  524. </ul>
  525. <p>Causes npm to install the package such that versions of npm prior to 1.4,
  526. such as the one included with node 0.8, can install the package. This
  527. eliminates all automatic deduping. If used with <code>global-style</code> this option
  528. will be preferred.</p>
  529. <!-- raw HTML omitted -->
  530. <!-- raw HTML omitted -->
  531. <h4 id="strict-peer-deps"><code>strict-peer-deps</code></h4>
  532. <ul>
  533. <li>Default: false</li>
  534. <li>Type: Boolean</li>
  535. </ul>
  536. <p>If set to <code>true</code>, and <code>--legacy-peer-deps</code> is not set, then <em>any</em>
  537. conflicting <code>peerDependencies</code> will be treated as an install failure, even
  538. if npm could reasonably guess the appropriate resolution based on non-peer
  539. dependency relationships.</p>
  540. <p>By default, conflicting <code>peerDependencies</code> deep in the dependency graph will
  541. be resolved using the nearest non-peer dependency specification, even if
  542. doing so will result in some packages receiving a peer dependency outside
  543. the range set in their package’s <code>peerDependencies</code> object.</p>
  544. <p>When such and override is performed, a warning is printed, explaining the
  545. conflict and the packages involved. If <code>--strict-peer-deps</code> is set, then
  546. this warning is treated as a failure.</p>
  547. <!-- raw HTML omitted -->
  548. <!-- raw HTML omitted -->
  549. <h4 id="package-lock"><code>package-lock</code></h4>
  550. <ul>
  551. <li>Default: true</li>
  552. <li>Type: Boolean</li>
  553. </ul>
  554. <p>If set to false, then ignore <code>package-lock.json</code> files when installing. This
  555. will also prevent <em>writing</em> <code>package-lock.json</code> if <code>save</code> is true.</p>
  556. <p>When package package-locks are disabled, automatic pruning of extraneous
  557. modules will also be disabled. To remove extraneous modules with
  558. package-locks disabled use <code>npm prune</code>.</p>
  559. <!-- raw HTML omitted -->
  560. <!-- raw HTML omitted -->
  561. <h4 id="omit"><code>omit</code></h4>
  562. <ul>
  563. <li>Default: ‘dev’ if the <code>NODE_ENV</code> environment variable is set to
  564. ‘production’, otherwise empty.</li>
  565. <li>Type: “dev”, “optional”, or “peer” (can be set multiple times)</li>
  566. </ul>
  567. <p>Dependency types to omit from the installation tree on disk.</p>
  568. <p>Note that these dependencies <em>are</em> still resolved and added to the
  569. <code>package-lock.json</code> or <code>npm-shrinkwrap.json</code> file. They are just not
  570. physically installed on disk.</p>
  571. <p>If a package type appears in both the <code>--include</code> and <code>--omit</code> lists, then
  572. it will be included.</p>
  573. <p>If the resulting omit list includes <code>'dev'</code>, then the <code>NODE_ENV</code> environment
  574. variable will be set to <code>'production'</code> for all lifecycle scripts.</p>
  575. <!-- raw HTML omitted -->
  576. <!-- raw HTML omitted -->
  577. <h4 id="ignore-scripts"><code>ignore-scripts</code></h4>
  578. <ul>
  579. <li>Default: false</li>
  580. <li>Type: Boolean</li>
  581. </ul>
  582. <p>If true, npm does not run scripts specified in package.json files.</p>
  583. <p>Note that commands explicitly intended to run a particular script, such as
  584. <code>npm start</code>, <code>npm stop</code>, <code>npm restart</code>, <code>npm test</code>, and <code>npm run-script</code>
  585. will still run their intended script if <code>ignore-scripts</code> is set, but they
  586. will <em>not</em> run any pre- or post-scripts.</p>
  587. <!-- raw HTML omitted -->
  588. <!-- raw HTML omitted -->
  589. <h4 id="audit"><code>audit</code></h4>
  590. <ul>
  591. <li>Default: true</li>
  592. <li>Type: Boolean</li>
  593. </ul>
  594. <p>When “true” submit audit reports alongside the current npm command to the
  595. default registry and all registries configured for scopes. See the
  596. documentation for <a href="../commands/npm-audit.html"><code>npm audit</code></a> for details on what is
  597. submitted.</p>
  598. <!-- raw HTML omitted -->
  599. <!-- raw HTML omitted -->
  600. <h4 id="bin-links"><code>bin-links</code></h4>
  601. <ul>
  602. <li>Default: true</li>
  603. <li>Type: Boolean</li>
  604. </ul>
  605. <p>Tells npm to create symlinks (or <code>.cmd</code> shims on Windows) for package
  606. executables.</p>
  607. <p>Set to false to have it not do this. This can be used to work around the
  608. fact that some file systems don’t support symlinks, even on ostensibly Unix
  609. systems.</p>
  610. <!-- raw HTML omitted -->
  611. <!-- raw HTML omitted -->
  612. <h4 id="fund"><code>fund</code></h4>
  613. <ul>
  614. <li>Default: true</li>
  615. <li>Type: Boolean</li>
  616. </ul>
  617. <p>When “true” displays the message at the end of each <code>npm install</code>
  618. acknowledging the number of dependencies looking for funding. See <a href="../commands/npm-fund.html"><code>npm fund</code></a> for details.</p>
  619. <!-- raw HTML omitted -->
  620. <!-- raw HTML omitted -->
  621. <h4 id="dry-run"><code>dry-run</code></h4>
  622. <ul>
  623. <li>Default: false</li>
  624. <li>Type: Boolean</li>
  625. </ul>
  626. <p>Indicates that you don’t want npm to make any changes and that it should
  627. only report what it would have done. This can be passed into any of the
  628. commands that modify your local installation, eg, <code>install</code>, <code>update</code>,
  629. <code>dedupe</code>, <code>uninstall</code>, as well as <code>pack</code> and <code>publish</code>.</p>
  630. <p>Note: This is NOT honored by other network related commands, eg <code>dist-tags</code>,
  631. <code>owner</code>, etc.</p>
  632. <!-- raw HTML omitted -->
  633. <!-- raw HTML omitted -->
  634. <h4 id="workspace"><code>workspace</code></h4>
  635. <ul>
  636. <li>Default:</li>
  637. <li>Type: String (can be set multiple times)</li>
  638. </ul>
  639. <p>Enable running a command in the context of the configured workspaces of the
  640. current project while filtering by running only the workspaces defined by
  641. this configuration option.</p>
  642. <p>Valid values for the <code>workspace</code> config are either:</p>
  643. <ul>
  644. <li>Workspace names</li>
  645. <li>Path to a workspace directory</li>
  646. <li>Path to a parent workspace directory (will result in selecting all
  647. workspaces within that folder)</li>
  648. </ul>
  649. <p>When set for the <code>npm init</code> command, this may be set to the folder of a
  650. workspace which does not yet exist, to create the folder and set it up as a
  651. brand new workspace within the project.</p>
  652. <p>This value is not exported to the environment for child processes.</p>
  653. <!-- raw HTML omitted -->
  654. <!-- raw HTML omitted -->
  655. <h4 id="workspaces"><code>workspaces</code></h4>
  656. <ul>
  657. <li>Default: null</li>
  658. <li>Type: null or Boolean</li>
  659. </ul>
  660. <p>Set to true to run the command in the context of <strong>all</strong> configured
  661. workspaces.</p>
  662. <p>Explicitly setting this to false will cause commands like <code>install</code> to
  663. ignore workspaces altogether. When not set explicitly:</p>
  664. <ul>
  665. <li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
  666. will link workspaces into the <code>node_modules</code> folder. - Commands that do
  667. other things (test, exec, publish, etc.) will operate on the root project,
  668. <em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
  669. </ul>
  670. <p>This value is not exported to the environment for child processes.</p>
  671. <!-- raw HTML omitted -->
  672. <!-- raw HTML omitted -->
  673. <h4 id="include-workspace-root"><code>include-workspace-root</code></h4>
  674. <ul>
  675. <li>Default: false</li>
  676. <li>Type: Boolean</li>
  677. </ul>
  678. <p>Include the workspace root when workspaces are enabled for a command.</p>
  679. <p>When false, specifying individual workspaces via the <code>workspace</code> config, or
  680. all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on
  681. the specified workspaces, and not on the root project.</p>
  682. <!-- raw HTML omitted -->
  683. <!-- raw HTML omitted -->
  684. <!-- raw HTML omitted -->
  685. <h3 id="algorithm">Algorithm</h3>
  686. <p>Given a <code>package{dep}</code> structure: <code>A{B,C}, B{C}, C{D}</code>,
  687. the npm install algorithm produces:</p>
  688. <pre lang="bash"><code>A
  689. +-- B
  690. +-- C
  691. +-- D
  692. </code></pre>
  693. <p>That is, the dependency from B to C is satisfied by the fact that A already
  694. caused C to be installed at a higher level. D is still installed at the top
  695. level because nothing conflicts with it.</p>
  696. <p>For <code>A{B,C}, B{C,D@1}, C{D@2}</code>, this algorithm produces:</p>
  697. <pre lang="bash"><code>A
  698. +-- B
  699. +-- C
  700. `-- D@2
  701. +-- D@1
  702. </code></pre>
  703. <p>Because B’s D@1 will be installed in the top-level, C now has to install
  704. D@2 privately for itself. This algorithm is deterministic, but different
  705. trees may be produced if two dependencies are requested for installation in
  706. a different order.</p>
  707. <p>See <a href="../configuring-npm/folders.html">folders</a> for a more detailed description of
  708. the specific folder structures that npm creates.</p>
  709. <h3 id="see-also">See Also</h3>
  710. <ul>
  711. <li><a href="../configuring-npm/folders.html">npm folders</a></li>
  712. <li><a href="../commands/npm-update.html">npm update</a></li>
  713. <li><a href="../commands/npm-audit.html">npm audit</a></li>
  714. <li><a href="../commands/npm-fund.html">npm fund</a></li>
  715. <li><a href="../commands/npm-link.html">npm link</a></li>
  716. <li><a href="../commands/npm-rebuild.html">npm rebuild</a></li>
  717. <li><a href="../using-npm/scripts.html">npm scripts</a></li>
  718. <li><a href="../commands/npm-config.html">npm config</a></li>
  719. <li><a href="../configuring-npm/npmrc.html">npmrc</a></li>
  720. <li><a href="../using-npm/registry.html">npm registry</a></li>
  721. <li><a href="../commands/npm-dist-tag.html">npm dist-tag</a></li>
  722. <li><a href="../commands/npm-uninstall.html">npm uninstall</a></li>
  723. <li><a href="../commands/npm-shrinkwrap.html">npm shrinkwrap</a></li>
  724. <li><a href="../configuring-npm/package-json.html">package.json</a></li>
  725. <li><a href="../using-npm/workspaces.html">workspaces</a></li>
  726. </ul>
  727. </div>
  728. <footer id="edit">
  729. <a href="https://github.com/npm/cli/edit/latest/docs/content/commands/npm-install.md">
  730. <svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
  731. <path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path>
  732. </svg>
  733. Edit this page on GitHub
  734. </a>
  735. </footer>
  736. </section>
  737. </body></html>