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