问题描述
当我开始遇到麻烦时,我试图通过npm
升级phonegap
.长话短说,我的计算机上有两个node_modules
目录.
I was attempting to upgrade phonegap
via npm
when I started running into trouble. Long story short, there are two node_modules
directories on my computer.
/usr/local/lib/node_modules
/usr/local/share/npm/lib/node_modules
当我运行npm upgrade -g phonegap
时,似乎npm
更新了/usr/local/lib/node_modules
中驻留的软件包的副本.但是,如果我which phonegap
我发现符号链接指向/usr/local/share/npm/lib/node_modules
上的较早安装.
When I run npm upgrade -g phonegap
, it appears that npm
updates the copy of the package that resides in /usr/local/lib/node_modules
. However, if I which phonegap
I find that the symlink points to the older installation at /usr/local/share/npm/lib/node_modules
.
此外,当我尝试安装独立软件包(例如express
)时,文件安装在/usr/local/lib/node_modules
目录的
Also, when I attempt to install a stand alone package such as express
, the files are installed in the /usr/local/lib/node_modules
directory,
两个问题:
- 在Mac OS X上哪个节点模块是正确的目录?
- Which is the proper directory for node modules on Mac OS X?
要点:安装node
的方法是否会影响配置?有很多选项.
Bonus points: Does the method of installing node
affect the configuration? There are a lot of options.
编辑:我发现在我的/usr/local/bin
中创建了符号链接,但是在我的$PATH
中在/usr/local/bin
之前的/usr/local/bin
中设置了.bash_profile
.我隐约记得在某个时候将该路径添加到我的个人资料中,但是我不确定为什么.
EDIT: I figured out that symlinks were being created in my /usr/local/bin
, but my .bash_profile
was setup with /usr/local/share/npm/bin
ahead of /usr/local/bin
in my $PATH
. I vaguely remember adding that path to my profile at some point, but I'm not sure why.
所以现在的问题变成了:我如何在计算机上最终得到两个不同的node_modules
目录?为什么我要在share/npm/lib
子目录中放置我的node_modules
而不是在/usr/local/lib
中?
So the question now becomes: how did I end up with two different node_modules
directories on my computer and why would I want to have my node_modules
in the share/npm/lib
subdirectory instead of right in /usr/local/lib
?
推荐答案
/usr/local/lib/node_modules
是全局安装的节点模块的正确目录.
/usr/local/lib/node_modules
is the correct directory for globally installed node modules.
/usr/local/share/npm/lib/node_modules
对我来说毫无意义.这里的一个问题是您很困惑,因为有两个名为 node_modules 的目录:
/usr/local/share/npm/lib/node_modules
makes no sense to me. One issue here is that you're confused because there are two directories called node_modules:
/usr/local/lib/node_modules
/usr/local/lib/node_modules/npm/node_modules
后者似乎是Node附带的节点模块,例如lodash
,而前者是我使用npm
安装的Node模块.
The latter seems to be node modules that came with Node, e.g., lodash
, when the former is Node modules that I installed using npm
.
这篇关于我的npm模块应在Mac OS X上的什么位置安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!