summaryrefslogtreecommitdiff
path: root/deps/npm/html/doc/cli/npm-install.html
blob: 1e20b3b61c0f4edfa96121fc6f757bfab0c5a202 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!doctype html>
<html>
  <title>npm-install</title>
  <meta http-equiv="content-type" value="text/html;utf-8">
  <link rel="stylesheet" type="text/css" href="../../static/style.css">
  <link rel="canonical" href="https://www.npmjs.org/doc/cli/npm-install.html">
  <script async=true src="../../static/toc.js"></script>

  <body>
    <div id="wrapper">

<h1><a href="../cli/npm-install.html">npm-install</a></h1> <p>Install a package</p>
<h2 id="synopsis">SYNOPSIS</h2>
<pre><code>npm install (with no args in a package dir)
npm install &lt;tarball file&gt;
npm install &lt;tarball url&gt;
npm install &lt;folder&gt;
npm install &lt;name&gt; [--save|--save-dev|--save-optional] [--save-exact]
npm install &lt;name&gt;@&lt;tag&gt;
npm install &lt;name&gt;@&lt;version&gt;
npm install &lt;name&gt;@&lt;version range&gt;
npm i (with any of the previous argument usage)
</code></pre><h2 id="description">DESCRIPTION</h2>
<p>This command installs a package, and any packages that it depends on. If the
package has a shrinkwrap file, the installation of dependencies will be driven
by that. See <a href="../cli/npm-shrinkwrap.html">npm-shrinkwrap(1)</a>.</p>
<p>A <code>package</code> is:</p>
<ul>
<li>a) a folder containing a program described by a package.json file</li>
<li>b) a gzipped tarball containing (a)</li>
<li>c) a url that resolves to (b)</li>
<li>d) a <code>&lt;name&gt;@&lt;version&gt;</code> that is published on the registry (see <code><a href="../misc/npm-registry.html">npm-registry(7)</a></code>) with (c)</li>
<li>e) a <code>&lt;name&gt;@&lt;tag&gt;</code> that points to (d)</li>
<li>f) a <code>&lt;name&gt;</code> that has a &quot;latest&quot; tag satisfying (e)</li>
<li>g) a <code>&lt;git remote url&gt;</code> that resolves to (b)</li>
</ul>
<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>
<ul>
<li><p><code>npm install</code> (in package directory, no arguments):</p>
<p>  Install the dependencies in the local node_modules folder.</p>
<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>
<p>  By default, <code>npm install</code> will install all modules listed as
  dependencies. With the <code>--production</code> flag,
  npm will not install modules listed in <code>devDependencies</code>.</p>
</li>
<li><p><code>npm install &lt;folder&gt;</code>:</p>
<p>  Install a package that is sitting in a folder on the filesystem.</p>
</li>
<li><p><code>npm install &lt;tarball file&gt;</code>:</p>
<p>  Install a package that is sitting on the filesystem.  Note: if you just want
  to link a dev directory into your npm root, you can do this more easily by
  using <code>npm link</code>.</p>
<p>  Example:</p>
<pre><code>    npm install ./package.tgz
</code></pre></li>
<li><p><code>npm install &lt;tarball url&gt;</code>:</p>
<p>  Fetch the tarball url, and then install it.  In order to distinguish between
  this and other options, the argument must start with &quot;http://&quot; or &quot;https://&quot;</p>
<p>  Example:</p>
<pre><code>    npm install https://github.com/indexzero/forever/tarball/v0.5.6
</code></pre></li>
<li><p><code>npm install &lt;name&gt; [--save|--save-dev|--save-optional]</code>:</p>
<p>  Do a <code>&lt;name&gt;@&lt;tag&gt;</code> install, where <code>&lt;tag&gt;</code> is the &quot;tag&quot; config. (See
  <code><a href="../misc/npm-config.html">npm-config(7)</a></code>.)</p>
<p>  In most cases, this will install the latest version
  of the module published on npm.</p>
<p>  Example:</p>
<pre><code>    npm install sax
</code></pre><p>  <code>npm install</code> takes 3 exclusive, optional flags which save or update
  the package version in your main package.json:</p>
<ul>
<li><p><code>--save</code>: Package will appear in your <code>dependencies</code>.</p>
</li>
<li><p><code>--save-dev</code>: Package will appear in your <code>devDependencies</code>.</p>
</li>
<li><p><code>--save-optional</code>: Package will appear in your <code>optionalDependencies</code>.</p>
<p>When using any of the above options to save dependencies to your
package.json, there is an additional, optional flag:</p>
</li>
<li><p><code>--save-exact</code>: Saved dependencies will be configured with an
exact version rather than using npm&#39;s default semver range
operator.</p>
<p>Examples:</p>
<pre><code>npm install sax --save
npm install node-tap --save-dev
npm install dtrace-provider --save-optional
npm install readable-stream --save --save-exact
</code></pre></li>
</ul>
</li>
</ul>
<pre><code>**Note**: If there is a file or folder named `&lt;name&gt;` in the current
working directory, then it will try to install that, and only try to
fetch the package by name if it is not valid.
</code></pre><ul>
<li><p><code>npm install &lt;name&gt;@&lt;tag&gt;</code>:</p>
<p>  Install the version of the package that is referenced by the specified tag.
  If the tag does not exist in the registry data for that package, then this
  will fail.</p>
<p>  Example:</p>
<pre><code>    npm install sax@latest
</code></pre></li>
<li><p><code>npm install &lt;name&gt;@&lt;version&gt;</code>:</p>
<p>  Install the specified version of the package.  This will fail if the version
  has not been published to the registry.</p>
<p>  Example:</p>
<pre><code>    npm install sax@0.1.1
</code></pre></li>
<li><p><code>npm install &lt;name&gt;@&lt;version range&gt;</code>:</p>
<p>  Install a version of the package matching the specified version range.  This
  will follow the same rules for resolving dependencies described in <code><a href="../files/package.json.html">package.json(5)</a></code>.</p>
<p>  Note that most version ranges must be put in quotes so that your shell will
  treat it as a single argument.</p>
<p>  Example:</p>
<pre><code>    npm install sax@&quot;&gt;=0.1.0 &lt;0.2.0&quot;
</code></pre></li>
<li><p><code>npm install &lt;git remote url&gt;</code>:</p>
<p>  Install a package by cloning a git remote url.  The format of the git
  url is:</p>
<pre><code>    &lt;protocol&gt;://[&lt;user&gt;@]&lt;hostname&gt;&lt;separator&gt;&lt;path&gt;[#&lt;commit-ish&gt;]
</code></pre><p>  <code>&lt;protocol&gt;</code> is one of <code>git</code>, <code>git+ssh</code>, <code>git+http</code>, or
  <code>git+https</code>.  If no <code>&lt;commit-ish&gt;</code> is specified, then <code>master</code> is
  used.</p>
<p>  Examples:</p>
<pre><code>    git+ssh://git@github.com:npm/npm.git#v1.0.27
    git+https://isaacs@github.com/npm/npm.git
    git://github.com/npm/npm.git#v1.0.27
</code></pre></li>
</ul>
<p>You may combine multiple arguments, and even multiple types of arguments.
For example:</p>
<pre><code>npm install sax@&quot;&gt;=0.1.0 &lt;0.2.0&quot; bench supervisor
</code></pre><p>The <code>--tag</code> argument will apply to all of the specified install targets. If a
tag with the given name exists, the tagged version is preferred over newer
versions.</p>
<p>The <code>--force</code> argument will force npm to fetch remote resources even if a
local copy exists on disk.</p>
<pre><code>npm install sax --force
</code></pre><p>The <code>--global</code> argument will cause npm to install the package globally
rather than locally.  See <code><a href="../files/npm-folders.html">npm-folders(5)</a></code>.</p>
<p>The <code>--link</code> argument will cause npm to link global installs into the
local space in some cases.</p>
<p>The <code>--no-bin-links</code> argument will prevent npm from creating symlinks for
any binaries the package might contain.</p>
<p>The <code>--no-optional</code> argument will prevent optional dependencies from
being installed.</p>
<p>The <code>--no-shrinkwrap</code> argument, which will ignore an available
shrinkwrap file and use the package.json instead.</p>
<p>The <code>--nodedir=/path/to/node/source</code> argument will allow npm to find the
node source code so that npm can compile native modules.</p>
<p>See <code><a href="../misc/npm-config.html">npm-config(7)</a></code>.  Many of the configuration params have some
effect on installation, since that&#39;s most of what npm does.</p>
<h2 id="algorithm">ALGORITHM</h2>
<p>To install a package, npm uses the following algorithm:</p>
<pre><code>install(where, what, family, ancestors)
fetch what, unpack to &lt;where&gt;/node_modules/&lt;what&gt;
for each dep in what.dependencies
  resolve dep to precise version
for each dep@version in what.dependencies
    not in &lt;where&gt;/node_modules/&lt;what&gt;/node_modules/*
    and not in &lt;family&gt;
  add precise version deps to &lt;family&gt;
  install(&lt;where&gt;/node_modules/&lt;what&gt;, dep, family)
</code></pre><p>For this <code>package{dep}</code> structure: <code>A{B,C}, B{C}, C{D}</code>,
this algorithm produces:</p>
<pre><code>A
+-- B
`-- C
    `-- D
</code></pre><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.</p>
<p>See <a href="../files/npm-folders.html">npm-folders(5)</a> for a more detailed description of the specific
folder structures that npm creates.</p>
<h3 id="limitations-of-npm-s-install-algorithm">Limitations of npm&#39;s Install Algorithm</h3>
<p>There are some very rare and pathological edge-cases where a cycle can
cause npm to try to install a never-ending tree of packages.  Here is
the simplest case:</p>
<pre><code>A -&gt; B -&gt; A&#39; -&gt; B&#39; -&gt; A -&gt; B -&gt; A&#39; -&gt; B&#39; -&gt; A -&gt; ...
</code></pre><p>where <code>A</code> is some version of a package, and <code>A&#39;</code> is a different version
of the same package.  Because <code>B</code> depends on a different version of <code>A</code>
than the one that is already in the tree, it must install a separate
copy.  The same is true of <code>A&#39;</code>, which must install <code>B&#39;</code>.  Because <code>B&#39;</code>
depends on the original version of <code>A</code>, which has been overridden, the
cycle falls into infinite regress.</p>
<p>To avoid this situation, npm flat-out refuses to install any
<code>name@version</code> that is already present anywhere in the tree of package
folder ancestors.  A more correct, but more complex, solution would be
to symlink the existing version into the new location.  If this ever
affects a real use-case, it will be investigated.</p>
<h2 id="see-also">SEE ALSO</h2>
<ul>
<li><a href="../files/npm-folders.html">npm-folders(5)</a></li>
<li><a href="../cli/npm-update.html">npm-update(1)</a></li>
<li><a href="../cli/npm-link.html">npm-link(1)</a></li>
<li><a href="../cli/npm-rebuild.html">npm-rebuild(1)</a></li>
<li><a href="../misc/npm-scripts.html">npm-scripts(7)</a></li>
<li><a href="../cli/npm-build.html">npm-build(1)</a></li>
<li><a href="../cli/npm-config.html">npm-config(1)</a></li>
<li><a href="../misc/npm-config.html">npm-config(7)</a></li>
<li><a href="../files/npmrc.html">npmrc(5)</a></li>
<li><a href="../misc/npm-registry.html">npm-registry(7)</a></li>
<li><a href="../cli/npm-tag.html">npm-tag(1)</a></li>
<li><a href="../cli/npm-rm.html">npm-rm(1)</a></li>
<li><a href="../cli/npm-shrinkwrap.html">npm-shrinkwrap(1)</a></li>
</ul>

</div>

<table border=0 cellspacing=0 cellpadding=0 id=npmlogo>
<tr><td style="width:180px;height:10px;background:rgb(237,127,127)" colspan=18>&nbsp;</td></tr>
<tr><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td><td style="width:40px;height:10px;background:#fff" colspan=4>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4>&nbsp;</td><td style="width:40px;height:10px;background:#fff" colspan=4>&nbsp;</td><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td><td colspan=6 style="width:60px;height:10px;background:#fff">&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4>&nbsp;</td></tr>
<tr><td colspan=2 style="width:20px;height:30px;background:#fff" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:20px;height:10px;background:#fff" rowspan=4 colspan=2>&nbsp;</td><td style="width:10px;height:20px;background:rgb(237,127,127)" rowspan=2>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:20px;height:10px;background:#fff" rowspan=3 colspan=2>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td></tr>
<tr><td style="width:10px;height:10px;background:#fff" rowspan=2>&nbsp;</td></tr>
<tr><td style="width:10px;height:10px;background:#fff">&nbsp;</td></tr>
<tr><td style="width:60px;height:10px;background:rgb(237,127,127)" colspan=6>&nbsp;</td><td colspan=10 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td></tr>
<tr><td colspan=5 style="width:50px;height:10px;background:#fff">&nbsp;</td><td style="width:40px;height:10px;background:rgb(237,127,127)" colspan=4>&nbsp;</td><td style="width:90px;height:10px;background:#fff" colspan=9>&nbsp;</td></tr>
</table>
<p id="footer">npm-install &mdash; npm@1.4.21</p>