277

After installing gulp.js via npm, I receive a no command 'gulp' found error when running the gulp command from the same directory it was installed into.

When looking under the node_modules/.bin/ directory, I can see the gulp executable there.

Is there something wrong with my npm installation?

Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
AndrewMcLagan
  • 13,459
  • 23
  • 91
  • 158

9 Answers9

527

That's perfectly normal. If you want gulp-cli available on the command line, you need to install it globally.

npm install --global gulp-cli

See the install instruction.

Also, node_modules/.bin/ isn't in your $PATH. But it is automatically added by npm when running npm scripts (see this blog post for reference).

So you could add scripts to your package.json file:

{
    "name": "your-app",
    "version": "0.0.1",
    "scripts": {
        "gulp": "gulp",
        "minify": "gulp minify"
    }
}

You could then run npm run gulp or npm run minify to launch gulp tasks.

DisgruntledGoat
  • 70,219
  • 68
  • 205
  • 290
Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
  • 2
    I am asked to run npm install -g gulp as sudo (Root . Admin) but if I do that then when I am exiting to normal user it cant find gulp command. I dont think its good to stay in root for everything I'd rather get my environment properly working. So anyone know what could cause this issue pls.. – landed Jul 30 '15 at 14:25
  • I guess it all depends on how/where node was installed. When using https://github.com/creationix/nvm, you don't need to be root to install global libs. – Brian Clozel Jul 30 '15 at 14:28
  • I think i used the installer on mac OSX to install nodejs.org I dont know the difference between nodejs and node @£$@ – landed Jul 30 '15 at 15:25
  • 4
    Please keep in mind that gulp itself is no longer a global package. Instead, global-cli is (npm -i -g gulp-cli) and that global gulp should actually be uninstalled first! – Ricardo Magalhães May 10 '16 at 09:46
14

I solved the issue without reinstalling node using the commands below:

$ npm uninstall --global gulp gulp-cli
$ rm /usr/local/share/man/man1/gulp.1
$ npm install --global gulp-cli
danday74
  • 52,471
  • 49
  • 232
  • 283
binz
  • 1,025
  • 8
  • 9
  • 1
    A slightly updated version of this worked for me, as I use NVM to manage my Node environment: `$ npm uninstall -g gulp gulp-cli` `$ rm /Users/[usrName]/.nvm/versions/node/[nodeVersion]/share/man/man1/gulp.1` `$ npm install -g gulp-cli` – JustJen Aug 08 '17 at 21:35
  • Global is a bad idea. – Michal Oct 20 '21 at 21:32
13

I actually have the same issue.

This link is probably my best guess:

nodejs vs node on ubuntu 12.04

I did that to resolve my problem:

sudo apt-get --purge remove node 
sudo apt-get --purge remove nodejs 
sudo apt-get install nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
Community
  • 1
  • 1
guboi
  • 197
  • 2
  • 13
  • 8
    You also need `sudo ln -s /usr/bin/nodejs /usr/bin/node` since so many apps/packages look for it there. – Seth May 12 '15 at 19:08
  • 1
    The `ln -s [target] [name|directory]` command creates a symbolic link ("alias" or "shortcut"). See http://linuxcommand.org/man_pages/ln1.html – defines Jul 28 '16 at 13:28
  • still not working here... Man, I kinda think that this is trivial. But this link from another SO page got the right answer. Just run it locally http://stackoverflow.com/questions/36457377/nodejs-gulp-not-found-after-npm-install?noredirect=1&lq=1 – swdev Oct 21 '16 at 04:15
8

I solved the issue removing gulp and installing gulp-cli again:

rm /usr/local/bin/gulp
npm install -g gulp-cli
4

if still not resolved try adding this to your package.js scripts

"scripts": { "gulp": "gulp" },

and run npm run gulp it will runt gulp scripts from gulpfile.js

Hanzla Habib
  • 3,457
  • 25
  • 25
2

Installing on a Mac - Sierra - After numerous failed attempts to install and run gulp globally via the command line using several different instructions I found I added this to my path and it worked:

export PATH=/usr/local/Cellar/node/7.6.0/libexec/npm/bin/:$PATH

I got that path from the text output when installing gulp.

G-Man
  • 1,138
  • 16
  • 20
2

Tried with sudo and it worked !!

sudo npm install --global gulp-cli
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Sopo
  • 1,577
  • 3
  • 16
  • 28
  • Please learn what `--global` means and how this doesn't fix the problem on other peoples computers. – Michal Oct 20 '21 at 21:31
1

I'm on lubuntu 19.10

I've used combination of previous answers, and didn't tweak the $PATH.

  1. npm uninstall --global gulp gulp-cli This removes any package if they are already there.
  2. sudo npm install --global gulp-cli Reinstall it as root user.

If you want to do copy and paste

npm uninstall --global gulp gulp-cli && sudo npm install --global gulp-cli 

should work

I guess --global is unnecessary here as it's installed using sudo, but I've used it just in case.

Minsky
  • 2,277
  • 10
  • 19
1

in my case there was only on issue, just put "gulp":"gulp" in the script portion, of package.json, and then use command npm run gulp.

israr
  • 332
  • 2
  • 4