npm安装不在/ usr / bin安装东西

时间:2014-04-15 17:46:03

标签: node.js ubuntu sails.js waterline ubuntu-13.04

我正在尝试使用以下命令安装SailsJS:

$ sudo npm install -g sails

可行,使用以下日志在/ home / brunoluiz / npm / lib / node_modules / sails中安装所有内容:

/home/brunoluiz/npm/bin/sails -> /home/brunoluiz/npm/lib/node_modules/sails/bin/sails.js
sails@0.9.16 /home/brunoluiz/npm/lib/node_modules/sails
├── connect-flash@0.1.1
├── pluralize@0.0.5
├── inflection@1.2.5
├── grunt-sails-linker@0.9.5
├── grunt-contrib-clean@0.4.1
├── node-uuid@1.4.0
├── async@0.2.9
├── grunt-contrib-concat@0.3.0
├── grunt-contrib-copy@0.4.1
├── grunt-contrib-coffee@0.7.0
├── ejs-locals@1.0.2
├── ejs@0.8.4
├── underscore.string@2.3.0
├── coffee-script@1.6.2
├── lodash@2.4.1
├── i18n@0.4.1 (debug@0.8.0, sprintf@0.1.3)
├── optimist@0.3.4 (wordwrap@0.0.2)
├── include-all@0.1.2 (underscore.string@2.3.1)
├── sails-disk@0.9.3 (waterline-criteria@0.9.7, lodash@2.3.0, fs-extra@0.8.1)
├── fs-extra@0.5.0 (jsonfile@0.0.1, ncp@0.2.7, mkdirp@0.3.5, rimraf@2.1.4)
├── connect-redis@1.4.5 (debug@0.8.0, redis@0.7.3)
├── grunt-contrib-jst@0.5.0 (lodash@1.0.1, grunt-lib-contrib@0.5.3)
├── glob@3.1.14 (inherits@1.0.0, graceful-fs@1.1.14, minimatch@0.2.14)
├── grunt-contrib-cssmin@0.6.1 (grunt-lib-contrib@0.6.1, clean-css@1.0.12)
├── grunt-cli@0.1.9 (resolve@0.3.1, nopt@1.0.10, findup-sync@0.1.3)
├── grunt-contrib-watch@0.4.4 (gaze@0.3.4, tiny-lr@0.0.4)
├── connect-mongo@0.3.2 (mongodb@1.2.14)
├── grunt-contrib-uglify@0.2.2 (grunt-lib-contrib@0.6.1, uglify-js@2.3.6)
├── waterline@0.9.16 (underscore@1.5.2, q@0.9.7, anchor@0.9.12)
├── grunt@0.4.1 (which@1.0.5, dateformat@1.0.2-1.2.3, eventemitter2@0.4.13, colors@0.6.2, hooker@0.2.3, async@0.1.22, nopt@1.0.10, minimatch@0.2.14, lodash@0.9.2, rimraf@2.0.3, coffee-script@1.3.3, underscore.string@2.2.1, iconv-lite@0.2.11, glob@3.1.21, findup-sync@0.1.3, js-yaml@2.0.5)
├── winston@0.7.1 (cycle@1.0.3, stack-trace@0.0.9, eyes@0.1.8, colors@0.6.2, pkginfo@0.3.0, request@2.16.6)
├── express@3.4.0 (methods@0.0.1, debug@0.8.0, range-parser@0.0.4, cookie-signature@1.0.1, fresh@0.2.0, buffer-crc32@0.2.1, cookie@0.1.0, mkdirp@0.3.5, commander@1.2.0, send@0.1.4, connect@2.9.0)
├── grunt-contrib-less@0.9.0 (grunt-lib-contrib@0.6.1, chalk@0.4.0, less@1.6.3)
└── socket.io@0.9.14 (base64id@0.1.0, policyfile@0.0.4, redis@0.7.3, socket.io-client@0.9.11)

问题是当您尝试使用风帆时:例如,您运行sails new project并且找不到风帆。稍微调查一下,我发现npm没有在/ usr / bin安装模块。这有什么理由吗?一些配置?

Karma模块也是如此。

我使用了ppa中的nodejs,创建了node的符号链接,并从官方install.sh脚本(https://www.npmjs.org/install.sh)安装了npm。

2 个答案:

答案 0 :(得分:15)

听起来您的npm安装配置为使用/home/brunoluiz/npm作为prefix,这意味着它会将符号链接放在{prefix}/bin中全局安装的软件包附带的CLI中

在默认安装中,prefix在Unix平台上是/usr/usr/local(在Windows上为%APPDATA%/npm)。

如果{prefix}/bin中没有$PATH,则您无法仅按名称执行此类CLI。

要查看有效的当前prefix值,请运行:

npm get prefix

您的选择是:

  • /home/brunoluiz/npm/bin添加到您的$PATH

  • prefix配置项的值更改为bin子文件夹已在$PATH中的文件夹; e.g:

    npm set prefix /usr       # Ubuntu; CLI symlinks are placed in /usr/bin
    npm set prefix /usr/local # OSX; CLIs symlinks are placed in /usr/local/bin

但是,请注意,您必须重新安装全局程序包,才能在新的{prefix}\bin位置创建符号链接。

答案 1 :(得分:0)

除了mklement0的答案之外,第一种解决方案(将npm二进制目录路径添加到PATH变量中)在Linux环境中以sudo前缀运行命令时会产生另一个问题。要解决此问题,还必须在secure_path的{​​{1}}中添加npm二进制目录路径。方法如下: Why can't sudo find a command after I added it to PATH?