node.js Mac OS X Mavericks 更新后无法使用 npm 进行全局安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22562041/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:02:54  来源:igfitidea点击:

Global installation with npm doesn't work after Mac OS X Mavericks update

node.jsmacosbashnpm

提问by Misha Reyzlin

After upgrading to OS X 10.9 Mavericks, node wasn't found anymore in bash. I think I installed it with brewa while ago.

升级到 OS X 10.9 Mavericks 后,在 bash 中找不到节点了。我想我brew不久前安装了它。

I decided to use the installer from node.js website. It went fine and both nodeand npmbecame available in bash. However, installing packages globally doesn't work.

我决定使用 node.js 网站上的安装程序。它运行良好,node并且npm在 bash 中可用。但是,全局安装软件包不起作用。

The npm -g binoutputs following path /usr/local/bin.

npm -g bin下面的路径输出/usr/local/bin

However, after running npm install -g karmaand invoking ls -la /usr/local/binI can't see a symlink to the path where karmaexecutable resides.

但是,在运行npm install -g karma和调用之后,ls -la /usr/local/bin我看不到karma可执行文件所在路径的符号链接。

Running npm -g rootreturns /usr/local/lib/node_modulesand after the installation I can see that karmamodule is there.

运行npm -g root返回/usr/local/lib/node_modules,安装后我可以看到该karma模块在那里。

Not sure what I else I could check. Thanks!

不知道我还能检查什么。谢谢!

采纳答案by Misha Reyzlin

The problem seems to have occured because I tried to install packages that were previously on my system. The symlinks weren't created, probably because of that. Once I removed the packages and re-installed them (or tried to install packages I haven't had), they were added to /usr/local/binas symlinks.

问题似乎已经发生,因为我试图安装以前在我的系统上的软件包。符号链接没有创建,可能是因为这个。一旦我删除了软件包并重新安装它们(或尝试安装我没有的软件包),它们就会被添加/usr/local/bin为符号链接。

回答by Greg

I found that the root cause of all of my npm install issues was the missing Xcode license agreement.

我发现所有 npm install 问题的根本原因是缺少 Xcode 许可协议。

After the Maverick update, XCode upgraded as well and if you don't launch XCode, the license agreement will be missing.

在 Maverick 更新后,XCode 也升级了,如果你不启动 XCode,许可协议将丢失。

Once I accepted the agreement, installs were successful.

一旦我接受了协议,安装就成功了。

回答by oraserrata

I had the same problem due to not accepting the xcode license after upgrading to Mavericks. I was able to accept the new xcode license by running the following:

由于升级到 Mavericks 后不接受 xcode 许可证,我遇到了同样的问题。通过运行以下命令,我能够接受新的 xcode 许可证:

sudo xcodebuild -license

须藤 xcodebuild -license

However, npm still was not working because symlink was not created, but trying to reinstall said npm was already there. I went ahead and:

然而,npm 仍然没有工作,因为符号链接没有被创建,但是尝试重新安装说 npm 已经存在。我继续说:

brew remove npm

brew 删除 npm

and then reinstalled with:

然后重新安装:

brew install npm

酿造安装npm

and I am back working again. Not a big fan of the reinstall, but I think the need to accept the xcode license left things in a hung state.

我又回来工作了。不太喜欢重新安装,但我认为需要接受 xcode 许可证使事情处于挂起状态。

回答by gardensnake

I had the same problem - npm did not work after upgrading to mavericks. I tried all the above steps, but was still stuck. Specifically, when I tried to re-install node, I got the error:

我遇到了同样的问题 - 升级到小牛后 npm 不起作用。我尝试了上述所有步骤,但仍然卡住了。具体来说,当我尝试重新安装节点时,出现错误:

Warning: The post-install step did not complete successfully You can try again using brew postinstall node

警告:安装后步骤未成功完成您可以再次尝试使用 brew postinstall node

But running brew postinstall noderesponded:

但跑步brew postinstall node回应:

Error: Permission denied - /usr/local/lib/node_modules/npm/AUTHORS

错误:权限被拒绝 - /usr/local/lib/node_modules/npm/AUTHORS

I tried removing all the node modules previously installed

我尝试删除以前安装的所有节点模块

sudo rm -rf /usr/local/lib/node_modules/

sudo rm -rf /usr/local/lib/node_modules/

and then uninstalling and reinstalling node

然后卸载并重新安装节点

and that finally got both node and npm working as before.

最终让 node 和 npm 像以前一样工作。

回答by Cheruvim

I had the same problem. After a maverick upgrade npm was not working, yet node itself was. I was not using the latest version as our team prefers to use 0.8.10.

我有同样的问题。在特立独行的升级之后,npm 不起作用,但节点本身却起作用了。我没有使用最新版本,因为我们的团队更喜欢使用 0.8.10。

In any case nvm, the node.js version manager, was still working. In this case I just reinstalled:

无论如何,node.js 版本管理器 nvm 仍在工作。在这种情况下,我只是重新安装了:

$ nvm install 0.8.21
######################################################################## 100.0%
Now using node v0.8.21
$ npm
Usage: npm <command>

where <command> is one of:
add-user, adduser, apihelp, author, bin, bugs, c, cache,
completion, config, ddp, dedupe, deprecate, docs, edit,
explore, faq, find, find-dupes, get, help, help-search,
home, i, info, init, install, isntall, issues, la, link,
list, ll, ln, login, ls, outdated, owner, pack, prefix,
prune, publish, r, rb, rebuild, remove, restart, rm, root,
run-script, s, se, search, set, show, shrinkwrap, star,
stars, start, stop, submodule, tag, test, tst, un,
uninstall, unlink, unpublish, unstar, up, update, version,
view, whoami

npm <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm faq          commonly asked questions
npm help <term>  search for help on <term>
npm help npm     involved overview

In the case where nvm was not working you might need to reinstall that, as well- ymmv

在 nvm 不工作的情况下,您可能还需要重新安装它 - ymmv

回答by Tom K. C. Chiu

I am not sure if my answer was too late or not. I found myself in a difference situation than you. Hope that my experience an hour ago helps you.

我不确定我的回答是否为时已晚。我发现自己的处境与你不同。希望我一小时前的经验对您有所帮助。

my npm version (npm -v) is 1.4.28. First, I installed node.js on a computer with an administrator account. Then I created a user with administrator rights. When I tried to check the version of npm running, I failed to do so.

我的 npm 版本 (npm -v) 是 1.4.28。首先,我在具有管理员帐户的计算机上安装了 node.js。然后我创建了一个具有管理员权限的用户。当我尝试检查 npm 正在运行的版本时,我没有这样做。

I searched the web and came across with this text. The original poster asked to check the path settings. I did not have node.js and npm installed with homebrew, another software that made me headache two months ago. I checked that I can run node. It is because node is located at /usr/local/bin, where all users have rights to execute programs. But for npm, it is in fact a link to ../lib/node_modules/npm/bin. However, the /usr/local/lib folder is not accessible by other users' but the administrator's account only.

我在网上搜索并遇到了这段文字。原始海报要求检查路径设置。我没有用 homebrew 安装 node.js 和 npm,这是两个月前让我头疼的另一个软件。我检查了我可以运行节点。因为node位于/usr/local/bin,所有用户都有执行程序的权限。但是对于 npm,它实际上是指向 ../lib/node_modules/npm/bin 的链接。但是,/usr/local/lib 文件夹不能被其他用户访问,只能由管理员帐户访问。

I "sudo -i" and granted "chmod a+x ../lib" to it. Surprisingly, all folders' within have the correct execution right. I suspected that is some sorts of bug. I exited sudo and tried "npm -v" again. Succeed.

我“sudo -i”并授予它“chmod a+x ../lib”。令人惊讶的是,其中的所有文件夹都具有正确的执行权限。我怀疑这是某种错误。我退出 sudo 并再次尝试“npm -v”。成功。

Hope that helps.

希望有帮助。

回答by Tacticus

In case the other solutions posted here do not work for you either, you may try out the approach suggested on thisGitHub page. With a complete re-installation according to the insturctions on the page, I finally got npm (and an application, vs-mda-remote to be precise) working.

如果此处发布的其他解决方案也不适合您,您可以尝试GitHub 页面上建议的方法。根据页面上的说明进行了完整的重新安装,我终于让 npm(和一个应用程序,准确地说是 vs-mda-remote)工作了。

EDIT: This happened after updating from Mavericks to Yosemite.

编辑:这是在从小牛队更新到优胜美地后发生的。