Windows上的全局npm安装位置? [英] Global npm install location on windows?
问题描述
我不确定100%,但是我相信我是从家用计算机和办公室PC上的Windows安装程序安装了节点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:\users\bjorn\appdata\roaming\npm\lessc
c:\users\bjorn\appdata\roaming\npm\lessc.cmd
在我的办公室PC上,它们位于程序文件下:
while on my office PC, they go under program files:
(dev) go|w:\srv> which lessc
c:\program files\nodejs\lessc
c:\program files\nodejs\lessc.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链接.
- Local install (default): puts stuff in ./node_modules of the current package root.
- Global install (with -g): puts stuff in /usr/local or wherever node is installed.
- Install it locally if you're going to require() it.
- Install it globally if you're going to run it on the command line. -> If you need both, then install it in both places, or use npm link.
前缀配置默认为节点安装的位置.在
在大多数系统中,这是/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上的默认位置,并且在实施替代之前我可能已经安装了Office版本.
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的同一绝对路径中,即(以管理员身份运行):
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):
mkdir %PROGRAMDATA%\npm
setx PATH "%PROGRAMDATA%\npm;%PATH%" /M
npm config set prefix %PROGRAMDATA%\npm
打开一个新的cmd.exe窗口,然后重新安装所有全局软件包.
open a new cmd.exe window and reinstall all global packages.
说明(按行号):
- 在一个合适的位置创建一个文件夹来保存全局变量(Microsoft是 坚持不应该写入ProgramFiles,因此似乎%PROGRAMDATA% 像是下一个逻辑位置.
- 目录必须位于路径上,因此请使用
setx .. /M
设置 系统路径(在HKEY_LOCAL_MACHINE下).这是需要您跑步的地方 在具有管理员权限的shell中. - 告诉
npm
使用此新路径. (注意:文件夹在以下位置的%PATH%中不可见 此外壳程序,因此您必须打开一个新窗口.
- 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.
- 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. - 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屋!