使用curl | sh安装npm时出现“sh: line 1: Moved: command not found”错误提示。

7

我尝试在Mac OSX Yosemite上使用命令安装npm

curl https://www.npmjs.org/install.sh | sh

我收到了以下信息:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    51  100    51    0     0    296      0 --:--:-- --:--:-- --:--:--   298

sh: line 1: Moved: command not found

有关如何解决这个问题的任何建议?

2
显然,你的回应不是一个shell脚本,而是以“Moved”开头的消息。当shell试图将其视为脚本时,就会出现错误。 - Charles Duffy
3
如果在末尾没有加上| sh,运行curl https://www.npmjs.org/install.sh将更加清楚明白。 - Charles Duffy
2个回答

13

你缺少curl命令的-L选项来跟随重定向。然而,你不需要再使用这种安装方法了,npm已经与node一起提供,如果你的发行版恰好将node的组件拆分开来,npm通常作为一个单独的软件包从你的发行版存储库中提供。


只想强调一下:如果您有一个比使用curl | sh模式更安全的替代方案,那么使用它是一个非常好的主意。 curl | sh可以变得很安全,但防御可能会很具有挑战性: https://spin.atomicobject.com/2016/12/12/security-spectrum-curl-sh/?utm_source=stackoverflow-ao&utm_campaign=security-spectrum-curl-sh&utm_medium=referral - zigg

2
我不得不找出我的节点应用程序安装在哪里,并将其添加到路径中。 我使用了此处列出的第一种方法:https://gist.github.com/isaacs/579814,结果发现 "node" 安装在 /home/myname/node-latest-install/~/local/bin 中。
将其添加到 PATH 中,然后执行 curl -L https://www.npmjs.org/install.sh | sh 就可以正常工作了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接