node.js 我的 npm 模块应该在 Mac OS X 上安装在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25045946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where should my npm modules be installed on Mac OS X?
提问by Ben Harold
I was attempting to upgrade phonegapvia npmwhen I started running into trouble. Long story short, there are two node_modulesdirectories on my computer.
我试图升级phonegap通过npm当我开始运行陷入困境。长话短说,node_modules我的电脑上有两个目录。
/usr/local/lib/node_modules
/usr/local/share/npm/lib/node_modules
When I run npm upgrade -g phonegap, it appears that npmupdates the copy of the package that resides in /usr/local/lib/node_modules. However, if I which phonegapI find that the symlink points to the older installation at /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.
Also, when I attempt to install a stand alone package such as express, the files are installed in the /usr/local/lib/node_modulesdirectory, but no symlink to the executable is created in anywhere in my $PATH.
此外,当我尝试安装一个独立的软件包时,例如express,文件安装在/usr/local/lib/node_modules目录中,但没有在我的$PATH.
Two questions:
两个问题:
- Which is the proper directory for node modules on Mac OS X?
How can I configurenpmto link executables in my$PATHwhen it installs software?
- Mac OS X 上节点模块的正确目录是哪个?
npm在$PATH安装软件时如何配置链接可执行文件?
Bonus points: Does the method of installing nodeaffect the configuration? There are a lot of options.
加分项:安装方法node会影响配置吗?有很多选择。
EDIT: I figured out that symlinks were being created in my /usr/local/bin, but my .bash_profilewas setup with /usr/local/share/npm/binahead of /usr/local/binin my $PATH. I vaguely remember adding that path to my profile at some point, but I'm not sure why.
编辑:我想通了,在我创建符号链接/usr/local/bin,但我.bash_profile是用设置/usr/local/share/npm/bin提前/usr/local/bin的我$PATH。我依稀记得在某个时候将该路径添加到我的个人资料中,但我不知道为什么。
So the question now becomes: how did I end up with two different node_modulesdirectories on my computer and why would I want to have my node_modulesin the share/npm/libsubdirectory instead of right in /usr/local/lib?
所以现在的问题变成了:我是如何node_modules在我的计算机上得到两个不同的目录的,为什么我想要node_modules在share/npm/lib子目录中而不是在/usr/local/lib.
回答by Thomas David Kehoe
/usr/local/lib/node_modulesis the correct directory for globally installed node modules.
/usr/local/lib/node_modules是全局安装的节点模块的正确目录。
/usr/local/share/npm/lib/node_modulesmakes no sense to me. One issue here is that you're confused because there are two directories called node_modules:
/usr/local/share/npm/lib/node_modules对我来说毫无意义。这里的一个问题是您感到困惑,因为有两个名为node_modules 的目录:
/usr/local/lib/node_modules/usr/local/lib/node_modules/npm/node_modules
/usr/local/lib/node_modules/usr/local/lib/node_modules/npm/node_modules
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.
后者似乎是 Node 附带的节点模块,例如,lodash当前者是我使用npm.
回答by ginna
Second Thomas David Kehoe, with the following caveat --
第二个托马斯大卫基霍,有以下警告——
If you are using node version manager (nvm), your global node modules will be stored under whatever version of node you are using at the time you saved the module.
如果您使用节点版本管理器 (nvm),您的全局节点模块将存储在您保存模块时使用的任何节点版本下。
So ~/.nvm/versions/node/{version}/lib/node_modules/.
所以~/.nvm/versions/node/{version}/lib/node_modules/。
回答by lazyTank
npm root -g
to check the npm_modules global location
检查 npm_modules 全局位置
回答by T04435
If you want to know the location of you NPM packages, you should:
如果你想知道你的 NPM 包的位置,你应该:
which npm // locate a program file in the user's path SEE man which
// OUTPUT SAMPLE
/usr/local/bin/npm
la /usr/local/bin/npm // la: aliased to ls -lAh SEE which la THEN man ls
lrwxr-xr-x 1 t04435 admin 46B 18 Sep 10:37 /usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
So given that npm is a NODE package itself, it is installed in the same location as other packages(EUREKA). So to confirm you should cd into node_modules and list the directory.
因此,鉴于 npm 本身就是一个节点包,它与其他包(EUREKA)安装在同一位置。所以要确认你应该 cd 进入 node_modules 并列出目录。
cd /usr/local/lib/node_modules/
ls
#SAMPLE OUTPUT
@angular npm .... all global npm packages installed
OR
或者
npm root -g
As per @anthonygore 's comment
根据@anthonygore 的评论


