20843d80e076f7e01090a0b1b4d2d6826d541986
[platform/upstream/nodejs.git] / deps / npm / man / man1 / npm-install.1
1 .\" Generated with Ronnjs 0.3.8
2 .\" http://github.com/kapouer/ronnjs/
3 .
4 .TH "NPM\-INSTALL" "1" "November 2013" "" ""
5 .
6 .SH "NAME"
7 \fBnpm-install\fR \-\- Install a package
8 .
9 .SH "SYNOPSIS"
10 .
11 .nf
12 npm install (with no args in a package dir)
13 npm install <tarball file>
14 npm install <tarball url>
15 npm install <folder>
16 npm install <name> [\-\-save|\-\-save\-dev|\-\-save\-optional]
17 npm install <name>@<tag>
18 npm install <name>@<version>
19 npm install <name>@<version range>
20 npm i (with any of the previous argument usage)
21 .
22 .fi
23 .
24 .SH "DESCRIPTION"
25 This command installs a package, and any packages that it depends on\. If the
26 package has a shrinkwrap file, the installation of dependencies will be driven
27 npm help by that\. See npm\-shrinkwrap\.
28 .
29 .P
30 A \fBpackage\fR is:
31 .
32 .IP "\(bu" 4
33 a) a folder containing a program described by a package\.json file
34 .
35 .IP "\(bu" 4
36 b) a gzipped tarball containing (a)
37 .
38 .IP "\(bu" 4
39 c) a url that resolves to (b)
40 .
41 .IP "\(bu" 4
42 d) a \fB<name>@<version>\fR that is published on the registry with (c)
43 .
44 .IP "\(bu" 4
45 e) a \fB<name>@<tag>\fR that points to (d)
46 .
47 .IP "\(bu" 4
48 f) a \fB<name>\fR that has a "latest" tag satisfying (e)
49 .
50 .IP "\(bu" 4
51 g) a \fB<git remote url>\fR that resolves to (b)
52 .
53 .IP "" 0
54 .
55 .P
56 Even if you never publish your package, you can still get a lot of
57 benefits of using npm if you just want to write a node program (a), and
58 perhaps if you also want to be able to easily install it elsewhere
59 after packing it up into a tarball (b)\.
60 .
61 .IP "\(bu" 4
62 \fBnpm install\fR (in package directory, no arguments):
63 .
64 .IP
65 Install the dependencies in the local node_modules folder\.
66 .
67 .IP
68 In global mode (ie, with \fB\-g\fR or \fB\-\-global\fR appended to the command),
69 it installs the current package context (ie, the current working
70 directory) as a global package\.
71 .
72 .IP
73 By default, \fBnpm install\fR will install all modules listed as
74 dependencies\. With the \fB\-\-production\fR flag,
75 npm will not install modules listed in \fBdevDependencies\fR\|\.
76 .
77 .IP "\(bu" 4
78 \fBnpm install <folder>\fR:
79 .
80 .IP
81 Install a package that is sitting in a folder on the filesystem\.
82 .
83 .IP "\(bu" 4
84 \fBnpm install <tarball file>\fR:
85 .
86 .IP
87 Install a package that is sitting on the filesystem\.  Note: if you just want
88 to link a dev directory into your npm root, you can do this more easily by
89 using \fBnpm link\fR\|\.
90 .
91 .IP
92 Example:
93 .
94 .IP "" 4
95 .
96 .nf
97   npm install \./package\.tgz
98 .
99 .fi
100 .
101 .IP "" 0
102
103 .
104 .IP "\(bu" 4
105 \fBnpm install <tarball url>\fR:
106 .
107 .IP
108 Fetch the tarball url, and then install it\.  In order to distinguish between
109 this and other options, the argument must start with "http://" or "https://"
110 .
111 .IP
112 Example:
113 .
114 .IP "" 4
115 .
116 .nf
117   npm install https://github\.com/indexzero/forever/tarball/v0\.5\.6
118 .
119 .fi
120 .
121 .IP "" 0
122
123 .
124 .IP "\(bu" 4
125 \fBnpm install <name> [\-\-save|\-\-save\-dev|\-\-save\-optional]\fR:
126 .
127 .IP
128 Do a \fB<name>@<tag>\fR install, where \fB<tag>\fR is the "tag" config\. (npm help  See \fBnpm\-config\fR\|\.)
129 .
130 .IP
131 In most cases, this will install the latest version
132 of the module published on npm\.
133 .
134 .IP
135 Example:
136 .
137 .IP
138       npm install sax
139 .
140 .IP
141 \fBnpm install\fR takes 3 exclusive, optional flags which save or update
142 the package version in your main package\.json:
143 .
144 .IP "\(bu" 4
145 \fB\-\-save\fR: Package will appear in your \fBdependencies\fR\|\.
146 .
147 .IP "\(bu" 4
148 \fB\-\-save\-dev\fR: Package will appear in your \fBdevDependencies\fR\|\.
149 .
150 .IP "\(bu" 4
151 \fB\-\-save\-optional\fR: Package will appear in your \fBoptionalDependencies\fR\|\.
152 .
153 .IP
154 Examples:
155 .
156 .IP
157   npm install sax \-\-save
158   npm install node\-tap \-\-save\-dev
159   npm install dtrace\-provider \-\-save\-optional
160 .
161 .IP
162 \fBNote\fR: If there is a file or folder named \fB<name>\fR in the current
163 working directory, then it will try to install that, and only try to
164 fetch the package by name if it is not valid\.
165 .
166 .IP "" 0
167
168 .
169 .IP "\(bu" 4
170 \fBnpm install <name>@<tag>\fR:
171 .
172 .IP
173 Install the version of the package that is referenced by the specified tag\.
174 If the tag does not exist in the registry data for that package, then this
175 will fail\.
176 .
177 .IP
178 Example:
179 .
180 .IP "" 4
181 .
182 .nf
183   npm install sax@latest
184 .
185 .fi
186 .
187 .IP "" 0
188
189 .
190 .IP "\(bu" 4
191 \fBnpm install <name>@<version>\fR:
192 .
193 .IP
194 Install the specified version of the package\.  This will fail if the version
195 has not been published to the registry\.
196 .
197 .IP
198 Example:
199 .
200 .IP "" 4
201 .
202 .nf
203   npm install sax@0\.1\.1
204 .
205 .fi
206 .
207 .IP "" 0
208
209 .
210 .IP "\(bu" 4
211 \fBnpm install <name>@<version range>\fR:
212 .
213 .IP
214 Install a version of the package matching the specified version range\.  This
215 npm help  will follow the same rules for resolving dependencies described in \fBpackage\.json\fR\|\.
216 .
217 .IP
218 Note that most version ranges must be put in quotes so that your shell will
219 treat it as a single argument\.
220 .
221 .IP
222 Example:
223 .
224 .IP
225       npm install sax@">=0\.1\.0 <0\.2\.0"
226 .
227 .IP "\(bu" 4
228 \fBnpm install <git remote url>\fR:
229 .
230 .IP
231 Install a package by cloning a git remote url\.  The format of the git
232 url is:
233 .
234 .IP
235       <protocol>://[<user>@]<hostname><separator><path>[#<commit\-ish>]
236 .
237 .IP
238 \fB<protocol>\fR is one of \fBgit\fR, \fBgit+ssh\fR, \fBgit+http\fR, or \fBgit+https\fR\|\.  If no \fB<commit\-ish>\fR is specified, then \fBmaster\fR is
239 used\.
240 .
241 .IP
242 Examples:
243 .
244 .IP "" 4
245 .
246 .nf
247   git+ssh://git@github\.com:isaacs/npm\.git#v1\.0\.27
248   git+https://isaacs@github\.com/isaacs/npm\.git
249   git://github\.com/isaacs/npm\.git#v1\.0\.27
250 .
251 .fi
252 .
253 .IP "" 0
254
255 .
256 .IP "" 0
257 .
258 .P
259 You may combine multiple arguments, and even multiple types of arguments\.
260 For example:
261 .
262 .IP "" 4
263 .
264 .nf
265 npm install sax@">=0\.1\.0 <0\.2\.0" bench supervisor
266 .
267 .fi
268 .
269 .IP "" 0
270 .
271 .P
272 The \fB\-\-tag\fR argument will apply to all of the specified install targets\. If a
273 tag with the given name exists, the tagged version is preferred over newer
274 versions\.
275 .
276 .P
277 The \fB\-\-force\fR argument will force npm to fetch remote resources even if a
278 local copy exists on disk\.
279 .
280 .IP "" 4
281 .
282 .nf
283 npm install sax \-\-force
284 .
285 .fi
286 .
287 .IP "" 0
288 .
289 .P
290 The \fB\-\-global\fR argument will cause npm to install the package globally
291 npm help  rather than locally\.  See \fBnpm\-folders\fR\|\.
292 .
293 .P
294 The \fB\-\-link\fR argument will cause npm to link global installs into the
295 local space in some cases\.
296 .
297 .P
298 The \fB\-\-no\-bin\-links\fR argument will prevent npm from creating symlinks for
299 any binaries the package might contain\.
300 .
301 .P
302 The \fB\-\-no\-shrinkwrap\fR argument, which will ignore an available
303 shrinkwrap file and use the package\.json instead\.
304 .
305 .P
306 The \fB\-\-nodedir=/path/to/node/source\fR argument will allow npm to find the
307 node source code so that npm can compile native modules\.
308 .
309 .P
310 npm help  See \fBnpm\-config\fR\|\.  Many of the configuration params have some
311 effect on installation, since that\'s most of what npm does\.
312 .
313 .SH "ALGORITHM"
314 To install a package, npm uses the following algorithm:
315 .
316 .IP "" 4
317 .
318 .nf
319 install(where, what, family, ancestors)
320 fetch what, unpack to <where>/node_modules/<what>
321 for each dep in what\.dependencies
322   resolve dep to precise version
323 for each dep@version in what\.dependencies
324     not in <where>/node_modules/<what>/node_modules/*
325     and not in <family>
326   add precise version deps to <family>
327   install(<where>/node_modules/<what>, dep, family)
328 .
329 .fi
330 .
331 .IP "" 0
332 .
333 .P
334 For this \fBpackage{dep}\fR structure: \fBA{B,C}, B{C}, C{D}\fR,
335 this algorithm produces:
336 .
337 .IP "" 4
338 .
339 .nf
340 A
341 +\-\- B
342 `\-\- C
343     `\-\- D
344 .
345 .fi
346 .
347 .IP "" 0
348 .
349 .P
350 That is, the dependency from B to C is satisfied by the fact that A
351 already caused C to be installed at a higher level\.
352 .
353 .P
354 npm help  See npm\-folders for a more detailed description of the specific
355 folder structures that npm creates\.
356 .
357 .SS "Limitations of npm&#39;s Install Algorithm"
358 There are some very rare and pathological edge\-cases where a cycle can
359 cause npm to try to install a never\-ending tree of packages\.  Here is
360 the simplest case:
361 .
362 .IP "" 4
363 .
364 .nf
365 A \-> B \-> A\' \-> B\' \-> A \-> B \-> A\' \-> B\' \-> A \-> \.\.\.
366 .
367 .fi
368 .
369 .IP "" 0
370 .
371 .P
372 where \fBA\fR is some version of a package, and \fBA\'\fR is a different version
373 of the same package\.  Because \fBB\fR depends on a different version of \fBA\fR
374 than the one that is already in the tree, it must install a separate
375 copy\.  The same is true of \fBA\'\fR, which must install \fBB\'\fR\|\.  Because \fBB\'\fR
376 depends on the original version of \fBA\fR, which has been overridden, the
377 cycle falls into infinite regress\.
378 .
379 .P
380 To avoid this situation, npm flat\-out refuses to install any \fBname@version\fR that is already present anywhere in the tree of package
381 folder ancestors\.  A more correct, but more complex, solution would be
382 to symlink the existing version into the new location\.  If this ever
383 affects a real use\-case, it will be investigated\.
384 .
385 .SH "SEE ALSO"
386 .
387 .IP "\(bu" 4
388 npm help  folders
389 .
390 .IP "\(bu" 4
391 npm help update
392 .
393 .IP "\(bu" 4
394 npm help link
395 .
396 .IP "\(bu" 4
397 npm help rebuild
398 .
399 .IP "\(bu" 4
400 npm help  scripts
401 .
402 .IP "\(bu" 4
403 npm help build
404 .
405 .IP "\(bu" 4
406 npm help config
407 .
408 .IP "\(bu" 4
409 npm help  config
410 .
411 .IP "\(bu" 4
412 npm help  npmrc
413 .
414 .IP "\(bu" 4
415 npm help  registry
416 .
417 .IP "\(bu" 4
418 npm help  folders
419 .
420 .IP "\(bu" 4
421 npm help tag
422 .
423 .IP "\(bu" 4
424 npm help rm
425 .
426 .IP "\(bu" 4
427 npm help shrinkwrap
428 .
429 .IP "" 0
430