npm 全局安装路径完全搞砸了 [英] npm global install path got totally screwed up

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

问题描述

我尝试处理安装新模块的 Node.js 权限问题,但在此过程中它完全搞砸了,所以当我全局安装某些东西时,它只是没有终端功能.例如,默认路径曾经是/usr/local/lib/node_modules,但现在每当我使用 npm -g 安装某些东西时,它都会将它安装在我的 OSX 主文件夹 (!!) 中,并且无法全局访问.我尝试删除所有内容,重新安装 Node.js,但没有任何帮助.这一切都发生在关注这个帖子

I tried dealing with the Node.js permission issue for installing new modules and in the process it got totally screwed up so when I install something globally, it just doesn't have a terminal function. For instance, the default path used to be /usr/local/lib/node_modules, but right now whenever I install something with npm -g, it installs it in my OSX home folder (!!) and it is not accessible globally. I tried removing everything, reinstalling Node.js, nothing helps. It all happened after following this thread

使用这些行:

sudo chown -R $(whoami) ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

请帮忙..我已经做了几个小时了:(

Please help.. I've been at it for hours now :(

推荐答案

听起来有几个问题.

现在,每当我使用 npm -g 安装某些东西时,它都会将其安装在我的 OSX 主文件夹 (!!) 中,并且无法全局访问.

right now whenever I install something with npm -g, it installs it in my OSX home folder (!!) and it is not accessible globally.

npm 在你的主目录中的 ~/.npm 中维护一个缓存.这不是安装位置,只是下载包和其他数据的缓存.如果这让你感到悲伤,你可以暂时摆脱它

npm maintains a cache in ~/.npm in your home directory. This is not an installation location, just a cache of downloaded packages and other data. If this is causing you grief, you can get rid of it temporarily with

npm 缓存清理

npm 将在运行时重新创建并重新填充缓存.

npm will recreate and repopulate the cache as it runs.

挽救这种情况的一种方法是下载并运行此脚本 <https://github.com/DomT4/scripts/blob/master/OSX_Node_Removal/terminatenode.sh> > 这将完全删除节点.然后,您可以使用安装程序 < 进行安装.http://nodejs.org/download/ > 或自制软件,无论您喜欢哪种.

One way to rescue the situation is to download and run this script < https://github.com/DomT4/scripts/blob/master/OSX_Node_Removal/terminatenode.sh > which will remove node completely. You can then install with the installer < http://nodejs.org/download/ > or homebrew, whichever you prefer.

不过,最后一点是,当你全局安装一个包时,你不能require它:你会得到新的命令.例如:

One last point, though, is that when you install a package globally, you cannot require it: you get new commands. For example:

<代码>$ jshint-bash: jshint: 命令未找到$ npm install -g jshint$ jshint$

现在我安装了 jshint 命令,可以用它来分析源文件;但我不能从任何代码中 require('jshint') ,因为它不在全局 node_modules 目录中.这是故意的;目标是让每个包都完整地声明其依赖项,这样就可以更轻松地将包从一台主机移动到另一台主机,而无需弄清楚需要在目标系统上安装哪些未记录的依赖项.

Now I have the jshint command installed and can use it to analyze source files; but I cannot require('jshint') from any code, because that doesn't look in the global node_modules directory. This is intentional; the goal is to make each package declare its dependencies completely, so it is easier to move a package from one host to another without having to figure out what undocumented dependencies need to be installed on the target system.

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

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