npm-install
选择命令行版本:
See Details
目录
概要
¥Synopsis
npm install [<package-spec> ...]aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
描述
¥Description
此命令安装一个包和它所依赖的任何包。如果包有一个包锁,或者一个 npm 收缩封装文件,或者一个 Yarn 锁文件,依赖的安装将由它驱动,遵循以下优先顺序:
¥This command installs a package and any packages that it depends on. If 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:
-
npm-shrinkwrap.json
-
package-lock.json
-
yarn.lock
见 package-lock.json 和 npm shrinkwrap
。
¥See package-lock.json and npm shrinkwrap
.
一个 package
是:
¥A package
is:
-
a) 包含由
package.json
文件描述的程序的文件夹¥a) a folder containing a program described by a
package.json
file -
b) 一个 gzipped tarball,包含 (a)
¥b) a gzipped tarball containing (a)
-
c) 解析为 (b) 的 url
¥c) a url that resolves to (b)
-
d) 在注册表上发布的
<name>@<version>
(参见registry
),带有 (c)¥d) a
<name>@<version>
that is published on the registry (seeregistry
) with (c) -
e) 指向 (d) 的
<name>@<tag>
(见npm dist-tag
)¥e) a
<name>@<tag>
(seenpm dist-tag
) that points to (d) -
f) 具有满足 (e) 的 "latest" 标签的
<name>
¥f) a
<name>
that has a "latest" tag satisfying (e) -
g) 解决为 (a) 的
<git remote url>
¥g) a
<git remote url>
that resolves to (a)
即使你从不发布你的包,如果你只是想写一个 node 程序(a),你仍然可以获得使用 npm 的很多好处,也许你还想在打包后能够轻松地安装它成一个 tarball (b)。
¥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).
-
npm install
(在包目录中,无参数):¥
npm install
(in a package directory, no arguments):将依赖安装到本地
node_modules
文件夹。¥Install the dependencies to the local
node_modules
folder.在全局模式下(即,将
-g
或--global
附加到命令中),它将当前包上下文(即当前工作目录)安装为全局包。¥In global mode (ie, with
-g
or--global
appended to the command), it installs the current package context (ie, the current working directory) as a global package.