node.js 如何修复 npm 的全局位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6685892/
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
How do I fix npm's global location?
提问by McLeopold
When I run
当我跑
npm ls -g
npm ls -g
I get back
我回来了
-> /usr/local/lib64/usr/local/bin
(empty)
Which is obviously incorrect. Using locateI can see my global modules are installed at /usr/lib64/node_modules. How do I go about correcting this issue? (I'm running gentoo amd64.)
这显然是不正确的。使用locate我可以看到我的全局模块安装在/usr/lib64/node_modules. 我该如何解决这个问题?(我正在运行 gentoo amd64。)
回答by cmaxo
npm uses a .npmrc file which should be in your home directory. (ie ~/.npmrc) In this file you should see a key value pair with the key being "prefix". Try setting the value to something like "/usr/lib64". So your .npmrc file would have the following in addition to whatever else you put in it:
npm 使用一个 .npmrc 文件,它应该在你的主目录中。(ie ~/.npmrc) 在这个文件中,你应该看到一个键值对,键是“前缀”。尝试将该值设置为“/usr/lib64”之类的值。因此,除了您放入的其他内容之外,您的 .npmrc 文件还将包含以下内容:
prefix = /usr/lib64
回答by Jason Lewis
For those on Windows the npmrcfile can be found in C:\path\to\nodejs\node_modules\npm\npmrc. You can change the prefixas mentioned in the answer by cmaxo. By default it's usually something like ${APPDATA}\npm.
对于那些在 Windows 上的npmrc文件,可以在C:\path\to\nodejs\node_modules\npm\npmrc. 您可以更改prefixcmaxo 的答案中提到的内容。默认情况下,它通常类似于${APPDATA}\npm.

