Quick fix for “gulp: command not found” error

If you use Gulp to run tasks, have you ever tried to run gulp on the command line, but gotten an error that says: gulp: command not found ?

Why is this happening?

Well, in order to run a package on your command line from any directory, it needs to be installed globally on your computer.

Here are a couple of fixes for this problem:

Install the gulp-cli globally

To run Gulp, you need two things:

So before trying to install Gulp in your project directory, you must first install the Gulp CLI globally. You can do this by typing in npm install gulp-cli -g.

Then you can install Gulp in the specific project directory by typing in npm install gulp.

Check that you have npm installed in the /usr/local directory

Are you still getting the error even if you have the Gulp CLI installed globally?

The problem might be caused by your global npm directory being set to the wrong location. The global npm directory is where your packages get installed when you install them globally.

You can check where it is by typing in npm root -g in the command line.

On PC, the directory might be: C:\Users\YOURNAME\AppData\Roaming\npm\node_modules

On a Mac, it should be something like: /usr/local/lib/node_modules/

For Mac users, if the root command returns a directory like /Users/YOURNAME/node_modules then this will cause the command not founderror.

To fix it, you can change what your npm root folder is set to by running: npm config set prefix /usr/local

Then you should be able to install the Gulp CLI globally and Gulp locally.

Enjoyed this post?
Tweet me about it! 😀
Want to learn how to build a website?

I'm making a course that will teach you how to build a real-world responsive website from a Figma design!

Learn more