codekingpro/portable-devtools
114k
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
116header.title .version {
117 font-size: 0.8em;
118 color: #666666;
119}
120
121footer#edit {
122 border-top: solid 1px #e1e4e8;
123 margin: 3em 0 4em 0;
124 padding-top: 2em;
125}
126
127table {
128 width: 100%;
129 margin: 1em 0;
130 border-radius: 6px;
131 border: 1px solid #e1e4e8;
132 overflow: hidden;
133 border-collapse: separate;
134 border-spacing: 0;
135}
136
137table thead {
138 background-color: #f6f8fa;
139}
140
141table tbody {
142 background-color: #ffffff;
143}
144
145table th,
146table td {
147 padding: 0.75em;
148 text-align: left;
149 border-right: 1px solid #e1e4e8;
150 border-bottom: 1px solid #e1e4e8;
151}
152
153table th:last-child,
154table td:last-child {
155 border-right: none;
156}
157
158table tbody tr:last-child td {
159 border-bottom: none;
160}
161
162table th {
163 font-weight: 600;
164 background-color: #f6f8fa;
165}
166
167table code {
168 white-space: nowrap;
169}
170
171</style>
172</head>
173<body>
174<div id="banner">
175<div id="rainbar"></div>
176<div id="logobar">
177<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
178<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
179<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
180</svg>
181<div class="title">
182npm command-line interface
183</div>
184</div>
185</div>
186
187<section id="content">
188<header class="title">
189<h1 id="----npm-install----11121">
190 <span>npm-install</span>
191 <span class="version">@11.12.1</span>
192</h1>
193<span class="description">Install a package</span>
194</header>
195
196<section id="table_of_contents">
197<h2 id="table-of-contents">Table of contents</h2>
198<div id="_table_of_contents"><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#description">Description</a></li><ul><li><a href="#how-npm-install-uses-package-lockjson">How <code>npm install</code> uses <code>package-lock.json</code></a></li></ul><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="#include"><code>include</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="#allow-git"><code>allow-git</code></a></li><li><a href="#audit"><code>audit</code></a></li><li><a href="#before"><code>before</code></a></li><li><a href="#min-release-age"><code>min-release-age</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="#cpu"><code>cpu</code></a></li><li><a href="#os"><code>os</code></a></li><li><a href="#libc"><code>libc</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>
199</section>
200
201<div id="_content"><h3 id="synopsis">Synopsis</h3>
202<pre><code class="language-bash">npm install [<package-spec> ...]
203
204aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
205</code></pre>
206<h3 id="description">Description</h3>
207<p>This command installs a package and any packages that it depends on.
208If the package has a package-lock, or an npm shrinkwrap file, or a yarn lock file, the installation of dependencies will be driven by that, respecting the following order of precedence:</p>
209<ul>
210<li><code>npm-shrinkwrap.json</code></li>
211<li><code>package-lock.json</code></li>
212<li><code>yarn.lock</code></li>
213</ul>
214<p>See <a href="../configuring-npm/package-lock-json.html">package-lock.json</a> and <a href="../commands/npm-shrinkwrap.html"><code>npm shrinkwrap</code></a>.</p>
215<h4 id="how-npm-install-uses-package-lockjson">How <code>npm install</code> uses <code>package-lock.json</code></h4>
216<p>When you run <code>npm install</code> without arguments, npm compares <code>package.json</code> and <code>package-lock.json</code>:</p>
217<ul>
218<li>
219<p><strong>If the lockfile's resolved versions satisfy the <code>package.json</code> ranges:</strong> npm uses the exact versions from <code>package-lock.json</code> to ensure reproducible builds across environments.</p>
220</li>
221<li>
222<p><strong>If the ranges don't match:</strong> npm resolves new versions that satisfy the <code>package.json</code> ranges and updates <code>package-lock.json</code> accordingly. This happens when you modify version ranges in <code>package.json</code> (e.g., changing <code>^7.0.0</code> to <code>^8.0.0</code>). Note that changing a range within the same major version (e.g., <code>^7.0.0</code> to <code>^7.1.0</code>) will only update the metadata in the lockfile if the currently installed version still satisfies the new range.</p>
223</li>
224</ul>
225<p>In essence, <code>package-lock.json</code> locks your dependencies to specific versions, but <code>package.json</code> is the source of truth for acceptable version ranges. When the lockfile's versions satisfy the <code>package.json</code> ranges, the lockfile wins. When they conflict, <code>package.json</code> wins and the lockfile is updated.</p>
226<p>If you want to install packages while ensuring that <code>package.json</code> is not modified and that both files are strictly in sync, use <a href="../commands/npm-ci.html"><code>npm ci</code></a> instead.</p>
227<p>A <code>package</code> is:</p>
228<ul>
229<li>a) a folder containing a program described by a <a href="../configuring-npm/package-json.html"><code>package.json</code></a> file</li>
230<li>b) a gzipped tarball containing (a)</li>
231<li>c) a url that resolves to (b)</li>
232<li>d) a <code><name>@<version></code> that is published on the registry (see <a href="../using-npm/registry.html"><code>registry</code></a>) with (c)</li>
233<li>e) a <code><name>@<tag></code> (see <a href="../commands/npm-dist-tag.html"><code>npm dist-tag</code></a>) that points to (d)</li>
234<li>f) a <code><name></code> that has a "latest" tag satisfying (e)</li>
235<li>g) a <code><git remote url></code> that resolves to (a)</li>
236</ul>
237<p>Even if you never publish your package, you can still get a lot of benefits of using npm if you just want to write a node program (a), and perhaps if you also want to be able to easily install it elsewhere after packing it up into a tarball (b).</p>
238<ul>
239<li>
240<p><code>npm install</code> (in a package directory, no arguments):</p>
241<p>Install the dependencies to the local <code>node_modules</code> folder.</p>
242<p>In global mode (ie, with <code>-g</code> or <code>--global</code> appended to the command), it installs the current package context (ie, the current working directory) as a global package.</p>
243<p>By default, <code>npm install</code> will install all modules listed as dependencies in <a href="../configuring-npm/package-json.html"><code>package.json</code></a>.</p>
244<p>With the <code>--production</code> flag (or when the <code>NODE_ENV</code> environment variable is set to <code>production</code>), npm will not install modules listed in <code>devDependencies</code>.
245To install all modules listed in both <code>dependencies</code> and <code>devDependencies</code> when <code>NODE_ENV</code> environment variable is set to <code>production</code>, you can use <code>--production=false</code>.</p>
246<blockquote>
247<p>NOTE: The <code>--production</code> flag has no particular meaning when adding a dependency to a project.</p>
248</blockquote>
249</li>
250<li>
251<p><code>npm install <folder></code>:</p>
252<p>If <code><folder></code> sits inside the root of your project, its dependencies will be installed and may be hoisted to the top-level <code>node_modules</code> as they would for other types of dependencies.
253If <code><folder></code> sits outside the root of your project, <em>npm will not install the package dependencies</em> in the directory <code><folder></code>, but it will create a symlink to <code><folder></code>.</p>
254<blockquote>
255<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>
256</blockquote>
257<p>Example:</p>
258<pre><code class="language-bash">npm install ../../other-package --install-links
259npm install ./sub-package
260</code></pre>
261</li>
262<li>
263<p><code>npm install <tarball file></code>:</p>
264<p>Install a package that is sitting on the filesystem.
265Note: if you just want to link a dev directory into your npm root, you can do this more easily by using <a href="../commands/npm-link.html"><code>npm link</code></a>.</p>
266<p>Tarball requirements:</p>
267<ul>
268<li>The filename <em>must</em> use <code>.tar</code>, <code>.tar.gz</code>, or <code>.tgz</code> as the extension.</li>
269<li>The package contents should reside in a subfolder inside the tarball (usually it is called <code>package/</code>).
270npm strips one directory layer when installing the package (an equivalent of <code>tar x --strip-components=1</code> is run).</li>
271<li>The package must contain a <code>package.json</code> file with <code>name</code> and <code>version</code> properties.</li>
272</ul>
273<p>Example:</p>
274<pre><code class="language-bash">npm install ./package.tgz
275</code></pre>
276</li>
277<li>
278<p><code>npm install <tarball url></code>:</p>
279<p>Fetch the tarball url, and then install it.
280In order to distinguish between this and other options, the argument must start with "http://" or "https://"</p>
281<p>Example:</p>
282<pre><code class="language-bash">npm install https://github.com/indexzero/forever/tarball/v0.5.6
283</code></pre>
284</li>
285<li>
286<p><code>npm install [<@scope>/]<name></code>:</p>
287<p>Do a <code><name>@<tag></code> install, where <code><tag></code> is the "tag" config.
288(See <a href="../using-npm/config#tag.html"><code>config</code></a>.
289The config's default value is <code>latest</code>.)</p>
290<p>In most cases, this will install the version of the modules tagged as <code>latest</code> on the npm registry.</p>
291<p><strong>Note:</strong> When installing by name without specifying a version or tag, npm prioritizes versions that match the current Node.js version based on the package's <code>engines</code> field. If the <code>latest</code> tag points to a version incompatible with your current Node.js version, npm will install the newest compatible version instead. To install a specific version regardless of <code>engines</code> compatibility, explicitly specify the version or tag: <code>npm install <name>@latest</code>.</p>
292<p>Example:</p>
293<pre><code class="language-bash">npm install sax
294</code></pre>
295<p><code>npm install</code> saves any specified packages into <code>dependencies</code> by default.
296Additionally, you can control where and how they get saved with some additional flags:</p>
297<ul>
298<li>
299<p><code>-P, --save-prod</code>: Package will appear in your <code>dependencies</code>.
300This is the default unless <code>-D</code> or <code>-O</code> are present.</p>
301</li>
302<li>
303<p><code>-D, --save-dev</code>: Package will appear in your <code>devDependencies</code>.</p>
304</li>
305<li>
306<p><code>--save-peer</code>: Package will appear in your <code>peerDependencies</code>.</p>
307</li>
308<li>
309<p><code>-O, --save-optional</code>: Package will appear in your
310<code>optionalDependencies</code>.</p>
311</li>
312<li>
313<p><code>--no-save</code>: Prevents saving to <code>dependencies</code>.</p>
314</li>
315</ul>
316<p>When using any of the above options to save dependencies to your package.json, there are two additional, optional flags:</p>
317<ul>
318<li>
319<p><code>-E, --save-exact</code>: Saved dependencies will be configured with an exact version rather than using npm's default semver range operator.</p>
320</li>
321<li>
322<p><code>-B, --save-bundle</code>: Saved dependencies will also be added to your <code>bundleDependencies</code> list.</p>
323</li>
324</ul>
325<p>Further, if you have an <code>npm-shrinkwrap.json</code> or <code>package-lock.json</code> then it will be updated as well.</p>
326<p><code><scope></code> is optional.
327The package will be downloaded from the registry associated with the specified scope.
328If no registry is associated with the given scope the default registry is assumed.
329See <a href="../using-npm/scope.html"><code>scope</code></a>.</p>
330<p>Note: if you do not include the @-symbol on your scope name, npm will interpret this as a GitHub repository instead, see below.
331Scopes names must also be followed by a slash.</p>
332<p>Examples:</p>
333<pre><code class="language-bash">npm install sax
334npm install githubname/reponame
335npm install @myorg/privatepackage
336npm install node-tap --save-dev
337npm install dtrace-provider --save-optional
338npm install readable-stream --save-exact
339npm install ansi-regex --save-bundle
340</code></pre>
341</li>
342<li>
343<p><code>npm install <alias>@npm:<name></code>:</p>
344<p>Install a package under a custom alias.
345Allows 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.
346Aliasing works only on your project and does not rename packages in transitive dependencies.
347Aliases should follow the naming conventions stated in <a href="https://www.npmjs.com/package/validate-npm-package-name#naming-rules"><code>validate-npm-package-name</code></a>.</p>
348<p>Examples:</p>
349<pre><code class="language-bash">npm install my-react@npm:react
350npm install jquery2@npm:jquery@2
351npm install jquery3@npm:jquery@3
352npm install npa@npm:npm-package-arg
353</code></pre>
354</li>
355<li>
356<p><code>npm install [<@scope>/]<name>@<tag></code>:</p>
357<p>Install the version of the package that is referenced by the specified tag.
358If the tag does not exist in the registry data for that package, then this will fail.</p>
359<p>Example:</p>
360<pre><code class="language-bash">npm install sax@latest
361npm install @myorg/mypackage@latest
362</code></pre>
363</li>
364<li>
365<p><code>npm install [<@scope>/]<name>@<version></code>:</p>
366<p>Install the specified version of the package.
367This will fail if the version has not been published to the registry.</p>
368<p>Example:</p>
369<pre><code class="language-bash">npm install sax@0.1.1
370npm install @myorg/privatepackage@1.5.0
371</code></pre>
372</li>
373<li>
374<p><code>npm install [<@scope>/]<name>@<version range></code>:</p>
375<p>Install a version of the package matching the specified version range.
376This will follow the same rules for resolving dependencies described in <a href="../configuring-npm/package-json.html"><code>package.json</code></a>.</p>
377<p>Note that most version ranges must be put in quotes so that your shell will treat it as a single argument.</p>
378<p>Example:</p>
379<pre><code class="language-bash">npm install sax@">=0.1.0 <0.2.0"
380npm install @myorg/privatepackage@"16 - 17"
381</code></pre>
382<p><strong>Prerelease versions:</strong> By default, version ranges only match stable versions. To include prerelease versions, they must be explicitly specified in the range. Prerelease versions are tied to a specific version triple (major.minor.patch). For example, <code>^1.2.3-beta.1</code> will only match prereleases for <code>1.2.x</code>, not <code>1.3.x</code>. To match all prereleases for a major version, use a range like <code>^1.0.0-0</code>, which will include all <code>1.x.x</code> prereleases.</p>
383<p>Example:</p>
384<pre><code class="language-bash">npm install package@^1.2.3-beta.1 # Matches 1.2.3-beta.1, 1.2.3-beta.2, 1.2.4-beta.1, etc.
385npm install package@^1.0.0-0 # Matches all 1.x.x prereleases and stable versions
386</code></pre>
387</li>
388<li>
389<p><code>npm install <git remote url></code>:</p>
390<p>Installs the package from the hosted git provider, cloning it with <code>git</code>.
391For a full git remote url, only that URL will be attempted.</p>
392<pre><code class="language-bash"><protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
393</code></pre>
394<p><code><protocol></code> is one of <code>git</code>, <code>git+ssh</code>, <code>git+http</code>, <code>git+https</code>, or
395<code>git+file</code>.</p>
396<p>If <code>#<commit-ish></code> is provided, it will be used to clone exactly that commit.
397If the commit-ish has the format <code>#semver:<semver></code>, <code><semver></code> 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.
398If neither <code>#<commit-ish></code> or <code>#semver:<semver></code> is specified, then the default branch of the repository is used.</p>
399<p>If the repository makes use of submodules, those submodules will be cloned as well.</p>
400<p>If the package being installed contains a <code>prepare</code> script, its <code>dependencies</code> and <code>devDependencies</code> will be installed, and the prepare script will be run, before the package is packaged and installed.</p>
401<p>The following git environment variables are recognized by npm and will be added to the environment when running git:</p>
402<ul>
403<li><code>GIT_ASKPASS</code></li>
404<li><code>GIT_EXEC_PATH</code></li>
405<li><code>GIT_PROXY_COMMAND</code></li>
406<li><code>GIT_SSH</code></li>
407<li><code>GIT_SSH_COMMAND</code></li>
408<li><code>GIT_SSL_CAINFO</code></li>
409<li><code>GIT_SSL_NO_VERIFY</code></li>
410</ul>
411<p>See the git man page for details.</p>
412<p>Examples:</p>
413<pre><code class="language-bash">npm install git+ssh://git@github.com:npm/cli.git#v1.0.27
414npm install git+ssh://git@github.com:npm/cli#pull/273
415npm install git+ssh://git@github.com:npm/cli#semver:^5.0
416npm install git+https://isaacs@github.com/npm/cli.git
417npm install git://github.com/npm/cli.git#v1.0.27
418GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git@github.com:npm/cli.git
419</code></pre>
420</li>
421<li>
422<p><code>npm install <githubname>/<githubrepo>[#<commit-ish>]</code>:</p>
423</li>
424<li>
425<p><code>npm install github:<githubname>/<githubrepo>[#<commit-ish>]</code>:</p>
426<p>Install the package at <code>https://github.com/githubname/githubrepo</code> by attempting to clone it using <code>git</code>.</p>
427<p>If <code>#<commit-ish></code> is provided, it will be used to clone exactly that commit.
428If the commit-ish has the format <code>#semver:<semver></code>, <code><semver></code> 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.
429If neither <code>#<commit-ish></code> or <code>#semver:<semver></code> is specified, then the default branch is used.</p>
430<p>As with regular git dependencies, <code>dependencies</code> and <code>devDependencies</code> will be installed if the package has a <code>prepare</code> script before the package is done installing.</p>
431<p>Examples:</p>
432<pre><code class="language-bash">npm install mygithubuser/myproject
433npm install github:mygithubuser/myproject
434</code></pre>
435</li>
436<li>
437<p><code>npm install gist:[<githubname>/]<gistID>[#<commit-ish>|#semver:<semver>]</code>:</p>
438<p>Install the package at <code>https://gist.github.com/gistID</code> by attempting to clone it using <code>git</code>.
439The GitHub username associated with the gist is optional and will not be saved in <code>package.json</code>.</p>
440<p>As with regular git dependencies, <code>dependencies</code> and <code>devDependencies</code> will be installed if the package has a <code>prepare</code> script before the package is done installing.</p>
441<p>Example:</p>
442<pre><code class="language-bash">npm install gist:101a11beef
443</code></pre>
444</li>
445<li>
446<p><code>npm install bitbucket:<bitbucketname>/<bitbucketrepo>[#<commit-ish>]</code>:</p>
447<p>Install the package at <code>https://bitbucket.org/bitbucketname/bitbucketrepo</code> by attempting to clone it using <code>git</code>.</p>
448<p>If <code>#<commit-ish></code> is provided, it will be used to clone exactly that commit.
449If the commit-ish has the format <code>#semver:<semver></code>, <code><semver></code> 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.
450If neither <code>#<commit-ish></code> or <code>#semver:<semver></code> is specified, then <code>master</code> is used.</p>
451<p>As with regular git dependencies, <code>dependencies</code> and <code>devDependencies</code> will be installed if the package has a <code>prepare</code> script before the package is done installing.</p>
452<p>Example:</p>
453<pre><code class="language-bash">npm install bitbucket:mybitbucketuser/myproject
454</code></pre>
455</li>
456<li>
457<p><code>npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]</code>:</p>
458<p>Install the package at <code>https://gitlab.com/gitlabname/gitlabrepo</code> by attempting to clone it using <code>git</code>.</p>
459<p>If <code>#<commit-ish></code> is provided, it will be used to clone exactly that commit.
460If the commit-ish has the format <code>#semver:<semver></code>, <code><semver></code> 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.
461If neither <code>#<commit-ish></code> or <code>#semver:<semver></code> is specified, then <code>master</code> is used.</p>
462<p>As with regular git dependencies, <code>dependencies</code> and <code>devDependencies</code> will be installed if the package has a <code>prepare</code> script before the package is done installing.</p>
463<p>Example:</p>
464<pre><code class="language-bash">npm install gitlab:mygitlabuser/myproject
465npm install gitlab:myusr/myproj#semver:^5.0
466</code></pre>
467</li>
468</ul>
469<p>You may combine multiple arguments and even multiple types of arguments.
470For example:</p>
471<pre><code class="language-bash">npm install sax@">=0.1.0 <0.2.0" bench supervisor
472</code></pre>
473<p>The <code>--tag</code> argument will apply to all of the specified install targets.
474If a tag with the given name exists, the tagged version is preferred over newer versions.</p>
475<p><strong>Note:</strong> The <code>--tag</code> option only affects packages specified on the command line. It does not override version ranges specified in <code>package.json</code>. For example, if <code>package.json</code> specifies <code>"foo": "^1.0.0"</code> and you run <code>npm install --tag beta</code>, npm will still install a version matching <code>^1.0.0</code> even if the <code>beta</code> tag points to a different version. To install a tagged version, specify the package explicitly: <code>npm install foo@beta</code>.</p>
476<p>The <code>--dry-run</code> argument will report in the usual way what the install would have done without actually installing anything.</p>
477<p>The <code>--package-lock-only</code> argument will only update the <code>package-lock.json</code>, instead of checking <code>node_modules</code> and downloading dependencies.</p>
478<p>The <code>-f</code> or <code>--force</code> argument will force npm to fetch remote resources even if a local copy exists on disk.</p>
479<pre><code class="language-bash">npm install sax --force
480</code></pre>
481<h3 id="configuration">Configuration</h3>
482<p>See the <a href="../using-npm/config.html"><code>config</code></a> help doc.
483Many of the configuration params have some effect on installation, since that's most of what npm does.</p>
484<p>These are some of the most common options related to installation.</p>
485<h4 id="save"><code>save</code></h4>
486<ul>
487<li>Default: <code>true</code> unless when using <code>npm update</code> where it defaults to <code>false</code></li>
488<li>Type: Boolean</li>
489</ul>
490<p>Save installed packages to a <code>package.json</code> file as dependencies.</p>
491<p>When used with the <code>npm rm</code> command, removes the dependency from
492<code>package.json</code>.</p>
493<p>Will also prevent writing to <code>package-lock.json</code> if set to <code>false</code>.</p>
494<h4 id="save-exact"><code>save-exact</code></h4>
495<ul>
496<li>Default: false</li>
497<li>Type: Boolean</li>
498</ul>
499<p>Dependencies saved to package.json will be configured with an exact version
500rather than using npm's default semver range operator.</p>
501<h4 id="global"><code>global</code></h4>
502<ul>
503<li>Default: false</li>
504<li>Type: Boolean</li>
505</ul>
506<p>Operates in "global" mode, so that packages are installed into the <code>prefix</code>
507folder instead of the current working directory. See
508<a href="../configuring-npm/folders.html">folders</a> for more on the differences in behavior.</p>
509<ul>
510<li>packages are installed into the <code>{prefix}/lib/node_modules</code> folder, instead
511of the current working directory.</li>
512<li>bin files are linked to <code>{prefix}/bin</code></li>
513<li>man pages are linked to <code>{prefix}/share/man</code></li>
514</ul>
515<h4 id="install-strategy"><code>install-strategy</code></h4>
516<ul>
517<li>Default: "hoisted"</li>
518<li>Type: "hoisted", "nested", "shallow", or "linked"</li>
519</ul>
520<p>Sets the strategy for installing packages in node_modules. hoisted
521(default): Install non-duplicated in top-level, and duplicated as necessary
522within directory structure. nested: (formerly --legacy-bundling) install in
523place, no hoisting. shallow (formerly --global-style) only install direct
524deps at top-level. linked: (experimental) install in node_modules/.store,
525link in place, unhoisted.</p>
526<h4 id="legacy-bundling"><code>legacy-bundling</code></h4>
527<ul>
528<li>Default: false</li>
529<li>Type: Boolean</li>
530<li>DEPRECATED: This option has been deprecated in favor of
531<code>--install-strategy=nested</code></li>
532</ul>
533<p>Instead of hoisting package installs in <code>node_modules</code>, install packages in
534the same manner that they are depended on. This may cause very deep
535directory structures and duplicate package installs as there is no
536de-duplicating. Sets <code>--install-strategy=nested</code>.</p>
537<h4 id="global-style"><code>global-style</code></h4>
538<ul>
539<li>Default: false</li>
540<li>Type: Boolean</li>
541<li>DEPRECATED: This option has been deprecated in favor of
542<code>--install-strategy=shallow</code></li>
543</ul>
544<p>Only install direct dependencies in the top level <code>node_modules</code>, but hoist
545on deeper dependencies. Sets <code>--install-strategy=shallow</code>.</p>
546<h4 id="omit"><code>omit</code></h4>
547<ul>
548<li>Default: 'dev' if the <code>NODE_ENV</code> environment variable is set to
549'production'; otherwise, empty.</li>
550<li>Type: "dev", "optional", or "peer" (can be set multiple times)</li>
551</ul>
552<p>Dependency types to omit from the installation tree on disk.</p>
553<p>Note that these dependencies <em>are</em> still resolved and added to the
554<code>package-lock.json</code> or <code>npm-shrinkwrap.json</code> file. They are just not
555physically installed on disk.</p>
556<p>If a package type appears in both the <code>--include</code> and <code>--omit</code> lists, then
557it will be included.</p>
558<p>If the resulting omit list includes <code>'dev'</code>, then the <code>NODE_ENV</code> environment
559variable will be set to <code>'production'</code> for all lifecycle scripts.</p>
560<h4 id="include"><code>include</code></h4>
561<ul>
562<li>Default:</li>
563<li>Type: "prod", "dev", "optional", or "peer" (can be set multiple times)</li>
564</ul>
565<p>Option that allows for defining which types of dependencies to install.</p>
566<p>This is the inverse of <code>--omit=<type></code>.</p>
567<p>Dependency types specified in <code>--include</code> will not be omitted, regardless of
568the order in which omit/include are specified on the command-line.</p>
569<h4 id="strict-peer-deps"><code>strict-peer-deps</code></h4>
570<ul>
571<li>Default: false</li>
572<li>Type: Boolean</li>
573</ul>
574<p>If set to <code>true</code>, and <code>--legacy-peer-deps</code> is not set, then <em>any</em>
575conflicting <code>peerDependencies</code> will be treated as an install failure, even
576if npm could reasonably guess the appropriate resolution based on non-peer
577dependency relationships.</p>
578<p>By default, conflicting <code>peerDependencies</code> deep in the dependency graph will
579be resolved using the nearest non-peer dependency specification, even if
580doing so will result in some packages receiving a peer dependency outside
581the range set in their package's <code>peerDependencies</code> object.</p>
582<p>When such an override is performed, a warning is printed, explaining the
583conflict and the packages involved. If <code>--strict-peer-deps</code> is set, then
584this warning is treated as a failure.</p>
585<h4 id="prefer-dedupe"><code>prefer-dedupe</code></h4>
586<ul>
587<li>Default: false</li>
588<li>Type: Boolean</li>
589</ul>
590<p>Prefer to deduplicate packages if possible, rather than choosing a newer
591version of a dependency.</p>
592<h4 id="package-lock"><code>package-lock</code></h4>
593<ul>
594<li>Default: true</li>
595<li>Type: Boolean</li>
596</ul>
597<p>If set to false, then ignore <code>package-lock.json</code> files when installing. This
598will also prevent <em>writing</em> <code>package-lock.json</code> if <code>save</code> is true.</p>
599<h4 id="package-lock-only"><code>package-lock-only</code></h4>
600<ul>
601<li>Default: false</li>
602<li>Type: Boolean</li>
603</ul>
604<p>If set to true, the current operation will only use the <code>package-lock.json</code>,
605ignoring <code>node_modules</code>.</p>
606<p>For <code>update</code> this means only the <code>package-lock.json</code> will be updated,
607instead of checking <code>node_modules</code> and downloading dependencies.</p>
608<p>For <code>list</code> this means the output will be based on the tree described by the
609<code>package-lock.json</code>, rather than the contents of <code>node_modules</code>.</p>
610<h4 id="foreground-scripts"><code>foreground-scripts</code></h4>
611<ul>
612<li>Default: <code>false</code> unless when using <code>npm pack</code> or <code>npm publish</code> where it
613defaults to <code>true</code></li>
614<li>Type: Boolean</li>
615</ul>
616<p>Run all build scripts (ie, <code>preinstall</code>, <code>install</code>, and <code>postinstall</code>)
617scripts for installed packages in the foreground process, sharing standard
618input, output, and error with the main npm process.</p>
619<p>Note that this will generally make installs run slower, and be much noisier,
620but can be useful for debugging.</p>
621<h4 id="ignore-scripts"><code>ignore-scripts</code></h4>
622<ul>
623<li>Default: false</li>
624<li>Type: Boolean</li>
625</ul>
626<p>If true, npm does not run scripts specified in package.json files.</p>
627<p>Note that commands explicitly intended to run a particular script, such as
628<code>npm start</code>, <code>npm stop</code>, <code>npm restart</code>, <code>npm test</code>, and <code>npm run</code> will still
629run their intended script if <code>ignore-scripts</code> is set, but they will <em>not</em>
630run any pre- or post-scripts.</p>
631<h4 id="allow-git"><code>allow-git</code></h4>
632<ul>
633<li>Default: "all"</li>
634<li>Type: "all", "none", or "root"</li>
635</ul>
636<p>Limits the ability for npm to fetch dependencies from git references. That
637is, dependencies that point to a git repo instead of a version or semver
638range. Please note that this could leave your tree incomplete and some
639packages may not function as intended or designed.</p>
640<p><code>all</code> allows any git dependencies to be fetched and installed. <code>none</code>
641prevents any git dependencies from being fetched and installed. <code>root</code> only
642allows git dependencies defined in your project's package.json to be fetched
643installed. Also allows git dependencies to be fetched for other commands
644like <code>npm view</code></p>
645<h4 id="audit"><code>audit</code></h4>
646<ul>
647<li>Default: true</li>
648<li>Type: Boolean</li>
649</ul>
650<p>When "true" submit audit reports alongside the current npm command to the
651default registry and all registries configured for scopes. See the
652documentation for <a href="../commands/npm-audit.html"><code>npm audit</code></a> for details on what is
653submitted.</p>
654<h4 id="before"><code>before</code></h4>
655<ul>
656<li>Default: null</li>
657<li>Type: null or Date</li>
658</ul>
659<p>If passed to <code>npm install</code>, will rebuild the npm tree such that only
660versions that were available <strong>on or before</strong> the given date are installed.
661If there are no versions available for the current set of dependencies, the
662command will error.</p>
663<p>If the requested version is a <code>dist-tag</code> and the given tag does not pass the
664<code>--before</code> filter, the most recent version less than or equal to that tag
665will be used. For example, <code>foo@latest</code> might install <code>foo@1.2</code> even though
666<code>latest</code> is <code>2.0</code>.</p>
667<p>This config cannot be used with: <code>min-release-age</code></p>
668<h4 id="min-release-age"><code>min-release-age</code></h4>
669<ul>
670<li>Default: null</li>
671<li>Type: null or Number</li>
672</ul>
673<p>If set, npm will build the npm tree such that only versions that were
674available more than the given number of days ago will be installed. If there
675are no versions available for the current set of dependencies, the command
676will error.</p>
677<p>This flag is a complement to <code>before</code>, which accepts an exact date instead
678of a relative number of days.</p>
679<p>This config cannot be used with: <code>before</code></p>
680<p>This value is not exported to the environment for child processes.</p>
681<h4 id="bin-links"><code>bin-links</code></h4>
682<ul>
683<li>Default: true</li>
684<li>Type: Boolean</li>
685</ul>
686<p>Tells npm to create symlinks (or <code>.cmd</code> shims on Windows) for package
687executables.</p>
688<p>Set to false to have it not do this. This can be used to work around the
689fact that some file systems don't support symlinks, even on ostensibly Unix
690systems.</p>
691<h4 id="fund"><code>fund</code></h4>
692<ul>
693<li>Default: true</li>
694<li>Type: Boolean</li>
695</ul>
696<p>When "true" displays the message at the end of each <code>npm install</code>
697acknowledging the number of dependencies looking for funding. See <a href="../commands/npm-fund.html"><code>npm fund</code></a> for details.</p>
698<h4 id="dry-run"><code>dry-run</code></h4>
699<ul>
700<li>Default: false</li>
701<li>Type: Boolean</li>
702</ul>
703<p>Indicates that you don't want npm to make any changes and that it should
704only report what it would have done. This can be passed into any of the
705commands that modify your local installation, eg, <code>install</code>, <code>update</code>,
706<code>dedupe</code>, <code>uninstall</code>, as well as <code>pack</code> and <code>publish</code>.</p>
707<p>Note: This is NOT honored by other network related commands, eg <code>dist-tags</code>,
708<code>owner</code>, etc.</p>
709<h4 id="cpu"><code>cpu</code></h4>
710<ul>
711<li>Default: null</li>
712<li>Type: null or String</li>
713</ul>
714<p>Override CPU architecture of native modules to install. Acceptable values
715are same as <code>cpu</code> field of package.json, which comes from <code>process.arch</code>.</p>
716<h4 id="os"><code>os</code></h4>
717<ul>
718<li>Default: null</li>
719<li>Type: null or String</li>
720</ul>
721<p>Override OS of native modules to install. Acceptable values are same as <code>os</code>
722field of package.json, which comes from <code>process.platform</code>.</p>
723<h4 id="libc"><code>libc</code></h4>
724<ul>
725<li>Default: null</li>
726<li>Type: null or String</li>
727</ul>
728<p>Override libc of native modules to install. Acceptable values are same as
729<code>libc</code> field of package.json</p>
730<h4 id="workspace"><code>workspace</code></h4>
731<ul>
732<li>Default:</li>
733<li>Type: String (can be set multiple times)</li>
734</ul>
735<p>Enable running a command in the context of the configured workspaces of the
736current project while filtering by running only the workspaces defined by
737this configuration option.</p>
738<p>Valid values for the <code>workspace</code> config are either:</p>
739<ul>
740<li>Workspace names</li>
741<li>Path to a workspace directory</li>
742<li>Path to a parent workspace directory (will result in selecting all
743workspaces within that folder)</li>
744</ul>
745<p>When set for the <code>npm init</code> command, this may be set to the folder of a
746workspace which does not yet exist, to create the folder and set it up as a
747brand new workspace within the project.</p>
748<p>This value is not exported to the environment for child processes.</p>
749<h4 id="workspaces"><code>workspaces</code></h4>
750<ul>
751<li>Default: null</li>
752<li>Type: null or Boolean</li>
753</ul>
754<p>Set to true to run the command in the context of <strong>all</strong> configured
755workspaces.</p>
756<p>Explicitly setting this to false will cause commands like <code>install</code> to
757ignore workspaces altogether. When not set explicitly:</p>
758<ul>
759<li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
760will link workspaces into the <code>node_modules</code> folder. - Commands that do
761other things (test, exec, publish, etc.) will operate on the root project,
762<em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
763</ul>
764<p>This value is not exported to the environment for child processes.</p>
765<h4 id="include-workspace-root"><code>include-workspace-root</code></h4>
766<ul>
767<li>Default: false</li>
768<li>Type: Boolean</li>
769</ul>
770<p>Include the workspace root when workspaces are enabled for a command.</p>
771<p>When false, specifying individual workspaces via the <code>workspace</code> config, or
772all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on
773the specified workspaces, and not on the root project.</p>
774<p>This value is not exported to the environment for child processes.</p>
775<h4 id="install-links"><code>install-links</code></h4>
776<ul>
777<li>Default: false</li>
778<li>Type: Boolean</li>
779</ul>
780<p>When set file: protocol dependencies will be packed and installed as regular
781dependencies instead of creating a symlink. This option has no effect on
782workspaces.</p>
783<h3 id="algorithm">Algorithm</h3>
784<p>Given a <code>package{dep}</code> structure: <code>A{B,C}, B{C}, C{D}</code>, the npm install algorithm produces:</p>
785<pre><code class="language-bash">A
786+-- B
787+-- C
788+-- D
789</code></pre>
790<p>That is, the dependency from B to C is satisfied by the fact that A already caused C to be installed at a higher level.
791D is still installed at the top level because nothing conflicts with it.</p>
792<p>For <code>A{B,C}, B{C,D@1}, C{D@2}</code>, this algorithm produces:</p>
793<pre><code class="language-bash">A
794+-- B
795+-- C
796 `-- D@2
797+-- D@1
798</code></pre>
799<p>Because B's D@1 will be installed in the top-level, C now has to install D@2 privately for itself.
800This algorithm is deterministic, but different trees may be produced if two dependencies are requested for installation in a different order.</p>
801<p>See <a href="../configuring-npm/folders.html">folders</a> for a more detailed description of the specific folder structures that npm creates.</p>
802<h3 id="see-also">See Also</h3>
803<ul>
804<li><a href="../configuring-npm/folders.html">npm folders</a></li>
805<li><a href="../commands/npm-update.html">npm update</a></li>
806<li><a href="../commands/npm-audit.html">npm audit</a></li>
807<li><a href="../commands/npm-fund.html">npm fund</a></li>
808<li><a href="../commands/npm-link.html">npm link</a></li>
809<li><a href="../commands/npm-rebuild.html">npm rebuild</a></li>
810<li><a href="../using-npm/scripts.html">npm scripts</a></li>
811<li><a href="../commands/npm-config.html">npm config</a></li>
812<li><a href="../configuring-npm/npmrc.html">npmrc</a></li>
813<li><a href="../using-npm/registry.html">npm registry</a></li>
814<li><a href="../commands/npm-dist-tag.html">npm dist-tag</a></li>
815<li><a href="../commands/npm-uninstall.html">npm uninstall</a></li>
816<li><a href="../commands/npm-shrinkwrap.html">npm shrinkwrap</a></li>
817<li><a href="../configuring-npm/package-json.html">package.json</a></li>
818<li><a href="../using-npm/workspaces.html">workspaces</a></li>
819</ul></div>
820
821<footer id="edit">
822<a href="https://github.com/npm/cli/edit/latest/docs/lib/content/commands/npm-install.md">
823<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
824<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>
825</svg>
826Edit this page on GitHub
827</a>
828</footer>
829</section>
830
831
832
833</body></html>