Windows 上的全局 npm 安装位置? [英] Global npm install location on windows?

查看:25
本文介绍了Windows 上的全局 npm 安装位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是 100% 确定,但我相信我在我的家用和办公室 PC 上从 Windows 安装程序安装了 node v5.

I'm not 100% sure, but I believe I installed node v5 from the windows installer on both my home and office PCs.

在我的家用 PC 上,全局安装发生在 %APPDATA% 下:

On my home PC global installs happen under %APPDATA%:

(dev) go|c:srv> which lessc
c:usersjornappdata
oaming
pmlessc
c:usersjornappdata
oaming
pmlessc.cmd

在我的办公室电脑上,它们位于程序文件下:

while on my office PC, they go under program files:

(dev) go|w:srv> which lessc
c:program files
odejslessc
c:program files
odejslessc.cmd

我需要向 PyCharm 的文件观察器提供许多这些全局工具的完整路径,并且由于我共享的项目文件在用户文件夹下没有全局资源是有意义的.

I need to provide the full path to a number of these global tools to PyCharm's file watcher, and since the project file i shared it would make sense to not have global resources under a user folder.

为什么全局安装最终会出现在不同的文件夹中,我如何将它们强制安装到所有团队成员共有的位置?

Why would the global installs end up in different folders, and how can I force them to a location that is common to all team members?

推荐答案

根据:https://docs.npmjs.com/files/folders

  • 本地安装(默认):将东西放在当前包根目录的 ./node_modules 中.
  • 全局安装(使用 -g):将内容放在/usr/local 或安装节点的任何位置.
  • 如果您要 require() 它,请在本地安装它.
  • 如果您要在命令行上运行它,请全局安装它.->如果两者都需要,则在两个地方都安装它,或者使用 npm 链接.

前缀配置默认为安装节点的位置.在大多数系统,这是/usr/local.在 Windows 上,这是准确的node.exe 二进制文件的位置.

The prefix config defaults to the location where node is installed. On most systems, this is /usr/local. On windows, this is the exact location of the node.exe binary.

文档可能有点过时,但它们解释了为什么全局安装会出现在不同的目录中:

The docs might be a little outdated, but they explain why global installs can end up in different directories:

(dev) go|c:srv> npm config ls -l | grep prefix
; prefix = "C:\Program Files\nodejs" (overridden)
prefix = "C:\Users\bjorn\AppData\Roaming\npm"

根据其他答案,似乎覆盖现在是 Windows 上的默认位置,并且我可能在实施此覆盖之前安装了我的办公室版本.

Based on the other answers, it may seem like the override is now the default location on Windows, and that I may have installed my office version prior to this override being implemented.

这也提出了一种让所有团队成员将全局变量存储在相对于他们的 PC 的相同绝对路径中的解决方案,即(以管理员身份运行):
(在 cmd 中运行,而不是在 PowerShell 中运行!)

This also suggests a solution for getting all team members to have globals stored in the same absolute path relative to their PC, i.e. (run as Administrator):
(Run this in cmd, not in PowerShell!)

mkdir %PROGRAMDATA%
pm
setx PATH "%PROGRAMDATA%
pm;%PATH%" /M
npm config set prefix %PROGRAMDATA%
pm

打开一个新的 cmd.exe 窗口并重新安装所有全局包.

open a new cmd.exe window and reinstall all global packages.

说明(by lineno.):

Explanation (by lineno.):

  1. 在合理的位置创建一个文件夹来保存全局变量(Microsoft 是坚持不应该写入 ProgramFiles,所以 %PROGRAMDATA% 似乎就像下一个合乎逻辑的地方.
  2. 目录需要在路径上,所以使用setx ../M来设置系统路径(在 HKEY_LOCAL_MACHINE 下).这就是需要你运行的这在具有管理员权限的 shell 中.
  3. 告诉 npm 使用这个新路径.(注意:文件夹在 %PATH% 中不可见这个外壳,所以你必须打开一个新窗口).
  1. Create a folder in a sensible location to hold the globals (Microsoft is adamant that you shouldn't write to ProgramFiles, so %PROGRAMDATA% seems like the next logical place.
  2. The directory needs to be on the path, so use setx .. /M to set the system path (under HKEY_LOCAL_MACHINE). This is what requires you to run this in a shell with administrator permissions.
  3. Tell npm to use this new path. (Note: folder isn't visible in %PATH% in this shell, so you must open a new window).

这篇关于Windows 上的全局 npm 安装位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆