在Mac中出现“-bash:gulp:命令未找到”的错误提示

23

我想在Mac上安装gulp,操作如下:

Is-iMac:~ itop$ npm root
/Users/itop/node_modules
Is-iMac:~ itop$ npm config set prefix /usr/local
Is-iMac:~ itop$ npm root -g
/usr/local/lib/node_modules
Is-iMac:~ itop$ sudo npm install -g gulp

安装后,我在终端中看到了这个错误:

npm WARN deprecated graceful-fs@3.0.8: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
npm WARN deprecated lodash@1.0.2: lodash@<3.0.0 is no longer maintained. Upgrade to lodash@^4.0.0.
npm WARN deprecated graceful-fs@1.2.3: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "gulp"
npm ERR! node v5.6.0
npm ERR! npm  v3.8.0
npm ERR! path /usr/local/bin/gulp
npm ERR! code EEXIST

npm ERR! Refusing to delete /usr/local/bin/gulp: ../lib/node_modules/gulp-cli/bin/gulp.js symlink target is not controlled by npm /usr/local
npm ERR! File exists: /usr/local/bin/gulp
npm ERR! Move it away, and try again.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/it/npm-debug.log

现在,当我在终端中输入gulp以开始/运行时,我会看到以下错误:

-bash: gulp: command not found

编辑: 我试着按照archie-voyageur的评论进行操作:

npm install --global gulp-cli

看到了这个错误:

/usr/local/bin/gulp -> /usr/local/lib/node_modules/gulp-cli/bin/gulp.js
npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--global" "gulp-cli"
npm ERR! node v5.6.0
npm ERR! npm  v3.8.0
npm ERR! path /usr/local/share/man/man1/gulp.1
npm ERR! code EEXIST

npm ERR! Refusing to delete /usr/local/share/man/man1/gulp.1: ../../../lib/node_modules/gulp/gulp.1 symlink target is not controlled by npm /usr/local
npm ERR! File exists: /usr/local/share/man/man1/gulp.1
npm ERR! Move it away, and try again.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/itop/npm-debug.log

这个问题该怎么解决?


@ArchieVoyageur:谢谢,我试一下这个,请看我的修改。 - ಠ_ಠ
1
我不确定“文件已存在,请将其移开并重试”这句话有什么不清楚的地方。 - Martin Tournoij
5个回答

83

我最近也遇到了这个问题,成功用以下方法解决:

$ npm uninstall --global gulp gulp-cli
$ rm /usr/local/share/man/man1/gulp.1
$ npm install --global gulp-cli

2
对我来说有效,2017年11月 - OSX Sierra。 - richtelford

8

前往

cd /usr/local/bin
ls -las

如果安装了gulp,请删除该目录。(sudo rm -rf gulp)重新安装gulp-cli。

===================================================================

如果不起作用,请彻底卸载 Node 和 npm,然后再试一次。
请按照以下链接中的逐步指南进行操作。 Node 和 npm 卸载逐步指南

0

我认为您的系统中已经安装了gulp,或者至少有一些与gulp相关的文件。只需执行npm uninstall --global gulp gulp-cli,然后再使用npm install --global gulp-cli重新安装即可。如果这样还不行,那么我就不知道您的系统出了什么问题。


我脑海中唯一能想到的是,你可以从系统中卸载Node,然后重新安装它。但是我对此并不抱有太大的希望,因为我不知道是什么导致了你的问题。 - franmartosr

0

在尝试了所有方法后,我终于成功安装了愚蠢的gulp

npm uninstall --global gulp gulp-cli

yarn global add gulp

-1
对我来说,只有当我使用npm而不是yarn安装gulp时,它才起作用。非常奇怪。。

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