通过bash使用npm在vagrant guest上安装gulp

时间:2015-01-23 21:12:46

标签: node.js bash vagrant gulp ansible

很难将这个分类。我使用Ansible来提供一个包含节点的精确64个框,包括节点:

- name: Node.js | Add the node.js PPA
  apt_repository: repo=ppa:chris-lea/node.js
  tags: nodejs

- name: Node.js | Install nodejs and npm
  apt: pkg=nodejs update_cache=yes
  tags: nodejs

配置完成后,我让Vagrant运行一个bash脚本,运行一些额外的配置,包括特定的npm包,比如gulp:

#!/bin/bash

sudo -u vagrant -i -- npm install gulp -g --no-bin-links --prefix "/project";

看起来有点像bash脚本:

==> project: gulp@3.8.10 /project/lib/node_modules/gulp
==> project: ├── pretty-hrtime@0.2.2
==> project: ├── interpret@0.3.10
==> project: ├── deprecated@0.0.1
==> project: ├── archy@1.0.0
==> project: ├── minimist@1.1.0
==> project: ├── tildify@1.0.0 (user-home@1.1.1)
==> project: ├── semver@4.2.0
==> project: ├── chalk@0.5.1 (escape-string-regexp@1.0.2, ansi-styles@1.1.0, supports-color@0.2.0, strip-ansi@0.3.0, has-ansi@0.1.0)
==> project: ├── v8flags@1.0.8
==> project: ├── orchestrator@0.3.7 (stream-consume@0.1.0, sequencify@0.0.7, end-of-stream@0.1.5)
==> project: ├── gulp-util@3.0.2 (beeper@1.0.0, array-differ@1.0.0, object-assign@2.0.0, array-uniq@1.0.2, lodash._reinterpolate@2.4.1, replace-ext@0.0.1, vinyl@0.4.6, through2@0.6.3, lodash.template@2.4.1, multipipe@0.1.2, dateformat@1.0.11)
==> project: ├── liftoff@0.13.6 (extend@1.3.0, flagged-respawn@0.3.1, resolve@1.0.0, findup-sync@0.1.3)
==> project: └── vinyl-fs@0.3.13 (graceful-fs@3.0.5, strip-bom@1.0.0, defaults@1.0.0, vinyl@0.4.6, mkdirp@0.5.0, through2@0.6.3, glob-stream@3.1.18, glob-watcher@0.0.6)

并且流浪汉似乎认为在那里吞咽:

vagrant@project:/project$ npm -v gulp
1.4.28

只是不可执行:

vagrant@project:/project$ gulp
No command 'gulp' found, did you mean:
 Command 'gslp' from package 'ghostscript' (main)
gulp: command not found

如果我在访客上手动安装gulp,然后就可以了:

vagrant@project:/project $ sudo npm install gulp -g
...
vagrant@project:/project$ gulp
[21:05:29] Using gulpfile /project/gulpfile.js
[21:05:29] Starting 'default'...
[21:05:29] Finished 'default' after 40 μs

所以,我以为我错过了一个符号链接或什么?我通过bash尝试了这个:

ln -s /usr/lib/node_modules/gulp/bin/gulp.js /usr/bin/gulp;

但是,同样的交易。

想法?

1 个答案:

答案 0 :(得分:1)

您的npm install -g命令表明您的gulp已安装在此目录中。 /项目/ LIB / node_modules /咽

尝试符号链接 ln -s /project/lib/node_modules/gulp/bin/gulp.js /usr/bin/gulp

/ project dir很可能不在你的PATH中。