全局安装

npm install -g nodemon
  • This installs nodemon globally.
  • You can run nodemon from any directory, but it won't appear(出现) in your local project's npm list.

本地安装

npm install lodash --save
  • This installs lodash locally(在本地,局部地) and adds it to your project's package.json dependencies.
  • Running npm list in your project directory will now show lodash.

列出已安装软件包

npm list 会列出当前目前下已安装的软件包(本地安装包),npm list -g会列出全局安装的软件包。

npm list -g --depth=0

--depth=0 选项将输出限制在顶级软件包范围内。

安装特定版本的软件包

npm install express@4.17.1
  • This command installs version 4.17.1 of the express package.
  • The specific version of the package will be added to your package.json under the dependencies section(区域).

全局安装特定版本

npm install -g eslint@7.32.0

全局软件包的安装位置

npm root -g

这将输出安装全局 npm 软件包的目录。常见位置包括:
Windows: C:\Users\<YourUsername>\AppData\Roaming\npm\node_modules
macOS/Linux: /usr/local/lib/node_modules

运行以下命令可查看 npm 配置,包括全局安装的前缀

npm config list

全局安装不会像本地安装那样维护 package.json 文件。每个全局安装的软件包都会在其目录中维护自己的 package.json 文件。但是,npm 本身不会创建一个单一的全局 package.json 来跟踪所有全局安装的软件包。

标签: none

评论已关闭