【问题标题】:npm doesn't install global modules correctnpm 没有正确安装全局模块
【发布时间】:2025-01-02 21:25:01
【问题描述】:

正确安装我的全局模块时出现问题。

我的系统

  • 操作系统:OS X Mountain Lion
  • node.js:0.10.18(包安装程序)

重现步骤

输入

npm install coffee -g(或任何其他模块)

输出

npm http GET https://registry.npmjs.org/coffee
npm http 200 https://registry.npmjs.org/coffee
{lots of dependencies}
coffee@0.0.1 /usr/local/lib/node_modules/coffee
├── node-getopt@0.2.3
├── modular-amd@0.1.2
├── chai@1.7.2 (assertion-error@1.0.0)
├── mocha@1.11.0 (growl@1.7.0, debug@0.7.2, commander@0.6.1, diff@1.0.2, mkdirp@0.3.5, ms@0.3.0, jade@0.26.3, glob@3.2.1)
├── express@3.2.6 (methods@0.0.1, fresh@0.1.0, range-parser@0.0.4, cookie-signature@1.0.1, buffer-crc32@0.2.1, cookie@0.1.0, debug@0.7.2, commander@0.6.1, mkdirp@0.3.4, send@0.1.0, connect@2.7.11)
├── sinon@1.7.3 (buster-format@0.5.6)
└── sinon-chai@2.4.0

输入

coffee

输出

-bash: coffee: command not found

其他信息

  • npm config get prefix/usr/local
  • /usr/local 的读/写访问权限:是的
  • $PATH/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
  • /usr/local/share/npm 存在:不存在
  • /usr/local/lib/node_modules/coffee 存在:是
  • /usr/local/bin/coffee 存在:没有

我还能做什么?

不会将咖啡的直接链接添加到我的$PATH-变量,因为那不是我的工作,那是npm 的工作!真的,当我可以自己做的时候,为什么还要使用 npm 呢?我把这个答案读了 100 遍,对此我无话可说,这并不违反 SO 的规则。

【问题讨论】:

  • 你是如何安装 node.js 的?从包装?通过自制软件?
  • 我使用了 nodejs.org 的包
  • npm 应该在 /usr/local/bin/coffee 创建指向 /usr/local/lib/node_modules/coffee/bin/coffee 的符号链接。如果它不这样做,那就错了……
  • 是的,我知道。我已经查看了权限是否错误,但是 root 和我的用户都具有读写访问权限。
  • 哇用户 vs 耐心,0-1,放松..

标签: macos node.js coffeescript npm


【解决方案1】:

如果你想全局安装 CoffeeScript(正如其中一个标签所建议的那样),你应该安装 coffee-script(不是coffee)。 此外,在 Mac 上安装全局模块需要 sudo。

命令:

sudo npm install coffee-script -g

输入

% coffee

输出

coffee>

【讨论】:

  • 我等了 3 周,因为有人阅读了 cmets,发现没有答案并创建了一个。谢谢!
  • 这对我不起作用。我尝试以各种方式(并使用 sudo)安装 grunt,并被告知它进入:~/local/lib/node_modules/grunt,但 bin 中没有任何内容,结果我得到 command-not-found。
  • 如果要安装 grunt 可执行文件,记得安装 grunt-cli (npmjs.org/package/grunt-cli) 而不是 grunt