1 npm-install(1) -- Install a package
2 ===================================
6 npm install (with no args in a package dir)
7 npm install <tarball file>
8 npm install <tarball url>
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 i (with any of the previous argument usage)
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).
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)
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).
38 * `npm install` (in package directory, no arguments):
40 Install the dependencies in the local node_modules folder.
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.
46 By default, `npm install` will install all modules listed as
47 dependencies. With the `--production` flag,
48 npm will not install modules listed in `devDependencies`.
50 * `npm install <folder>`:
52 Install a package that is sitting in a folder on the filesystem.
54 * `npm install <tarball file>`:
56 Install a package that is sitting on the filesystem. Note: if you just want
57 to link a dev directory into your npm root, you can do this more easily by
62 npm install ./package.tgz
64 * `npm install <tarball url>`:
66 Fetch the tarball url, and then install it. In order to distinguish between
67 this and other options, the argument must start with "http://" or "https://"
71 npm install https://github.com/indexzero/forever/tarball/v0.5.6
73 * `npm install <name> [--save|--save-dev|--save-optional]`:
75 Do a `<name>@<tag>` install, where `<tag>` is the "tag" config. (See
78 In most cases, this will install the latest version
79 of the module published on npm.
85 `npm install` takes 3 exclusive, optional flags which save or update
86 the package version in your main package.json:
88 * `--save`: Package will appear in your `dependencies`.
90 * `--save-dev`: Package will appear in your `devDependencies`.
92 * `--save-optional`: Package will appear in your `optionalDependencies`.
96 npm install sax --save
97 npm install node-tap --save-dev
98 npm install dtrace-provider --save-optional
101 **Note**: If there is a file or folder named `<name>` in the current
102 working directory, then it will try to install that, and only try to
103 fetch the package by name if it is not valid.
105 * `npm install <name>@<tag>`:
107 Install the version of the package that is referenced by the specified tag.
108 If the tag does not exist in the registry data for that package, then this
113 npm install sax@latest
115 * `npm install <name>@<version>`:
117 Install the specified version of the package. This will fail if the version
118 has not been published to the registry.
122 npm install sax@0.1.1
124 * `npm install <name>@<version range>`:
126 Install a version of the package matching the specified version range. This
127 will follow the same rules for resolving dependencies described in `package.json(5)`.
129 Note that most version ranges must be put in quotes so that your shell will
130 treat it as a single argument.
134 npm install sax@">=0.1.0 <0.2.0"
136 * `npm install <git remote url>`:
138 Install a package by cloning a git remote url. The format of the git
141 <protocol>://[<user>@]<hostname><separator><path>[#<commit-ish>]
143 `<protocol>` is one of `git`, `git+ssh`, `git+http`, or
144 `git+https`. If no `<commit-ish>` is specified, then `master` is
149 git+ssh://git@github.com:isaacs/npm.git#v1.0.27
150 git+https://isaacs@github.com/isaacs/npm.git
151 git://github.com/isaacs/npm.git#v1.0.27
153 You may combine multiple arguments, and even multiple types of arguments.
156 npm install sax@">=0.1.0 <0.2.0" bench supervisor
158 The `--tag` argument will apply to all of the specified install targets. If a
159 tag with the given name exists, the tagged version is preferred over newer
162 The `--force` argument will force npm to fetch remote resources even if a
163 local copy exists on disk.
165 npm install sax --force
167 The `--global` argument will cause npm to install the package globally
168 rather than locally. See `npm-folders(5)`.
170 The `--link` argument will cause npm to link global installs into the
171 local space in some cases.
173 The `--no-bin-links` argument will prevent npm from creating symlinks for
174 any binaries the package might contain.
176 The `--no-optional` argument will prevent optional dependencies from
179 The `--no-shrinkwrap` argument, which will ignore an available
180 shrinkwrap file and use the package.json instead.
182 The `--nodedir=/path/to/node/source` argument will allow npm to find the
183 node source code so that npm can compile native modules.
185 See `npm-config(7)`. Many of the configuration params have some
186 effect on installation, since that's most of what npm does.
190 To install a package, npm uses the following algorithm:
192 install(where, what, family, ancestors)
193 fetch what, unpack to <where>/node_modules/<what>
194 for each dep in what.dependencies
195 resolve dep to precise version
196 for each dep@version in what.dependencies
197 not in <where>/node_modules/<what>/node_modules/*
199 add precise version deps to <family>
200 install(<where>/node_modules/<what>, dep, family)
202 For this `package{dep}` structure: `A{B,C}, B{C}, C{D}`,
203 this algorithm produces:
210 That is, the dependency from B to C is satisfied by the fact that A
211 already caused C to be installed at a higher level.
213 See npm-folders(5) for a more detailed description of the specific
214 folder structures that npm creates.
216 ### Limitations of npm's Install Algorithm
218 There are some very rare and pathological edge-cases where a cycle can
219 cause npm to try to install a never-ending tree of packages. Here is
222 A -> B -> A' -> B' -> A -> B -> A' -> B' -> A -> ...
224 where `A` is some version of a package, and `A'` is a different version
225 of the same package. Because `B` depends on a different version of `A`
226 than the one that is already in the tree, it must install a separate
227 copy. The same is true of `A'`, which must install `B'`. Because `B'`
228 depends on the original version of `A`, which has been overridden, the
229 cycle falls into infinite regress.
231 To avoid this situation, npm flat-out refuses to install any
232 `name@version` that is already present anywhere in the tree of package
233 folder ancestors. A more correct, but more complex, solution would be
234 to symlink the existing version into the new location. If this ever
235 affects a real use-case, it will be investigated.