The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / npm / doc / cli / install.md @ 5aef65a9

History | View | Annotate | Download (7.16 KB)

1
npm-install(1) -- Install a package
2
===================================
3

    
4
## SYNOPSIS
5

    
6
    npm install (with no args in a package dir)
7
    npm install <tarball file>
8
    npm install <tarball url>
9
    npm install <folder>
10
    npm install <name> [--save|--save-dev|--save-optional]
11
    npm install <name>@<tag>
12
    npm install <name>@<version>
13
    npm install <name>@<version range>
14
    npm install <name>@<version range>
15

    
16
## DESCRIPTION
17

    
18
This command installs a package, and any packages that it depends on. If the
19
package has a shrinkwrap file, the installation of dependencies will be driven
20
by that. See npm-shrinkwrap(1).
21

    
22
A `package` is:
23

    
24
* a) a folder containing a program described by a package.json file
25
* b) a gzipped tarball containing (a)
26
* c) a url that resolves to (b)
27
* d) a `<name>@<version>` that is published on the registry with (c)
28
* e) a `<name>@<tag>` that points to (d)
29
* f) a `<name>` that has a "latest" tag satisfying (e)
30
* g) a `<git remote url>` that resolves to (b)
31

    
32
Even if you never publish your package, you can still get a lot of
33
benefits of using npm if you just want to write a node program (a), and
34
perhaps if you also want to be able to easily install it elsewhere
35
after packing it up into a tarball (b).
36

    
37

    
38
* `npm install` (in package directory, no arguments):
39

    
40
    Install the dependencies in the local node_modules folder.
41

    
42
    In global mode (ie, with `-g` or `--global` appended to the command),
43
    it installs the current package context (ie, the current working
44
    directory) as a global package.
45

    
46

    
47
* `npm install <folder>`:
48

    
49
    Install a package that is sitting in a folder on the filesystem.
50

    
51
* `npm install <tarball file>`:
52

    
53
    Install a package that is sitting on the filesystem.  Note: if you just want
54
    to link a dev directory into your npm root, you can do this more easily by
55
    using `npm link`.
56

    
57
    Example:
58

    
59
          npm install ./package.tgz
60

    
61
* `npm install <tarball url>`:
62

    
63
    Fetch the tarball url, and then install it.  In order to distinguish between
64
    this and other options, the argument must start with "http://" or "https://"
65

    
66
    Example:
67

    
68
          npm install https://github.com/indexzero/forever/tarball/v0.5.6
69

    
70
* `npm install <name> [--save|--save-dev|--save-optional]`:
71

    
72
    Do a `<name>@<tag>` install, where `<tag>` is the "tag" config. (See
73
    `npm-config(1)`.)
74

    
75
    In most cases, this will install the latest version
76
    of the module published on npm.
77

    
78
    Example:
79

    
80
          npm install sax
81

    
82
    `npm install` takes 3 exclusive, optional flags which save or update
83
    the package version in your main package.json:
84

    
85
    * `--save`: Package will appear in your `dependencies`.
86

    
87
    * `--save-dev`: Package will appear in your `devDependencies`.
88

    
89
    * `--save-optional`: Package will appear in your `optionalDependencies`.
90

    
91
    Examples:
92

    
93
          npm install sax --save
94
          npm install node-tap --save-dev
95
          npm install dtrace-provider --save-optional
96

    
97

    
98
    **Note**: If there is a file or folder named `<name>` in the current
99
    working directory, then it will try to install that, and only try to
100
    fetch the package by name if it is not valid.
101

    
102
* `npm install <name>@<tag>`:
103

    
104
    Install the version of the package that is referenced by the specified tag.
105
    If the tag does not exist in the registry data for that package, then this
106
    will fail.
107

    
108
    Example:
109

    
110
          npm install sax@latest
111

    
112
* `npm install <name>@<version>`:
113

    
114
    Install the specified version of the package.  This will fail if the version
115
    has not been published to the registry.
116

    
117
    Example:
118

    
119
          npm install sax@0.1.1
120

    
121
* `npm install <name>@<version range>`:
122

    
123
    Install a version of the package matching the specified version range.  This
124
    will follow the same rules for resolving dependencies described in `npm-json(1)`.
125

    
126
    Note that most version ranges must be put in quotes so that your shell will
127
    treat it as a single argument.
128

    
129
    Example:
130

    
131
          npm install sax@">=0.1.0 <0.2.0"
132

    
133
* `npm install <git remote url>`:
134

    
135
    Install a package by cloning a git remote url.  The format of the git
136
    url is:
137

    
138
          <protocol>://[<user>@]<hostname><separator><path>[#<commit-ish>]
139

    
140
    `<protocol>` is one of `git`, `git+ssh`, `git+http`, or
141
    `git+https`.  If no `<commit-ish>` is specified, then `master` is
142
    used.
143

    
144
    Examples:
145

    
146
          git+ssh://git@github.com:isaacs/npm.git#v1.0.27
147
          git+https://isaacs@github.com/isaacs/npm.git
148
          git://github.com/isaacs/npm.git#v1.0.27
149

    
150
You may combine multiple arguments, and even multiple types of arguments.
151
For example:
152

    
153
    npm install sax@">=0.1.0 <0.2.0" bench supervisor
154

    
155
The `--tag` argument will apply to all of the specified install targets.
156

    
157
The `--force` argument will force npm to fetch remote resources even if a
158
local copy exists on disk.
159

    
160
    npm install sax --force
161

    
162
The `--global` argument will cause npm to install the package globally
163
rather than locally.  See `npm-folders(1)`.
164

    
165
The `--link` argument will cause npm to link global installs into the
166
local space in some cases.
167

    
168
The `--no-bin-links` argument will prevent npm from creating symlinks for
169
any binaries the package might contain.
170

    
171
See `npm-config(1)`.  Many of the configuration params have some
172
effect on installation, since that's most of what npm does.
173

    
174
## ALGORITHM
175

    
176
To install a package, npm uses the following algorithm:
177

    
178
    install(where, what, family, ancestors)
179
    fetch what, unpack to <where>/node_modules/<what>
180
    for each dep in what.dependencies
181
      resolve dep to precise version
182
    for each dep@version in what.dependencies
183
        not in <where>/node_modules/<what>/node_modules/*
184
        and not in <family>
185
      add precise version deps to <family>
186
      install(<where>/node_modules/<what>, dep, family)
187

    
188
For this `package{dep}` structure: `A{B,C}, B{C}, C{D}`,
189
this algorithm produces:
190

    
191
    A
192
    +-- B
193
    `-- C
194
        `-- D
195

    
196
That is, the dependency from B to C is satisfied by the fact that A
197
already caused C to be installed at a higher level.
198

    
199
See npm-folders(1) for a more detailed description of the specific
200
folder structures that npm creates.
201

    
202
### Limitations of npm's Install Algorithm
203

    
204
There are some very rare and pathological edge-cases where a cycle can
205
cause npm to try to install a never-ending tree of packages.  Here is
206
the simplest case:
207

    
208
    A -> B -> A' -> B' -> A -> B -> A' -> B' -> A -> ...
209

    
210
where `A` is some version of a package, and `A'` is a different version
211
of the same package.  Because `B` depends on a different version of `A`
212
than the one that is already in the tree, it must install a separate
213
copy.  The same is true of `A'`, which must install `B'`.  Because `B'`
214
depends on the original version of `A`, which has been overridden, the
215
cycle falls into infinite regress.
216

    
217
To avoid this situation, npm flat-out refuses to install any
218
`name@version` that is already present anywhere in the tree of package
219
folder ancestors.  A more correct, but more complex, solution would be
220
to symlink the existing version into the new location.  If this ever
221
affects a real use-case, it will be investigated.
222

    
223
## SEE ALSO
224

    
225
* npm-folders(1)
226
* npm-update(1)
227
* npm-link(1)
228
* npm-rebuild(1)
229
* npm-scripts(1)
230
* npm-build(1)
231
* npm-config(1)
232
* npm-registry(1)
233
* npm-folders(1)
234
* npm-tag(1)
235
* npm-rm(1)
236
* npm-shrinkwrap(1)