Skip to content

Instantly share code, notes, and snippets.

@LeandroGabrielAyala
Last active March 13, 2023 17:58
Show Gist options
  • Save LeandroGabrielAyala/f8ec289e5acf66434b052eb516941851 to your computer and use it in GitHub Desktop.
Save LeandroGabrielAyala/f8ec289e5acf66434b052eb516941851 to your computer and use it in GitHub Desktop.
The "gulp" command is not found or does not work on node_modules (npm)

I recently wanted to install a new NPM module (that is Gulp). I followed the getting started guide and ran the needed command but it didn’t worked and I felt desperate… but I finally found the solution!

To give you a little context: I ran the following command for installing Gulp (a node package module) globally:

npm install -g gulp

The installation succeed but when I ran this gulp command in the command line I got a "gulp: command not found" error. It appeared that it installed “Gulp” in my local folder that is /Users/YOURUSERNAME/node_modules and not in the global NPM folder.

You can check this by running this command: npm root or npm root -g, which was returning my personal directory /Users/YOURUSERNAME/node_modules and not the expected /usr/local/lib/node_modules.

After some trial & error, I finally found the solution. You have to change the “npm config prefix” like so:

npm config set prefix /usr/local

Then when I re-ran npm root -g, I got the correct root folder: /usr/local/lib/node_modules

When I reinstalled Gulp globally (with the -g param) it finally worked and appeared that it was now correctly installed in the global NPM folder. Yeay!

@sanjeev-io
Copy link

I have been having exactly the same issue for last couple of days. After going in circles with changing path and other stuff suggested, nothing worked. Then I tried this approach and worked flawlessly, so a huge thank you.

@cetricokola
Copy link

Try npm link gulp

@IonatanMocan
Copy link

thank you! it helped!

@KhilkoDmitryCDR
Copy link

Leonardo, i have passed 2 days for this and you just saved my mind .I love you man , thank you.

@masxdesign
Copy link

life saver!

@alliwalk
Copy link

I found this solution was also shared on StackOverflow and this blog post. Worked for me as well.

@jacobproffer
Copy link

Try npm link gulp

This did it for me. Thank you.

@vincentherail
Copy link

Try npm link gulp

Work for me to ! thank's

@amrsmind
Copy link

Thanks a lot for this answer

@diegograziano
Copy link

You´re a livesaver. Thanks a lot!

@cetricokola
Copy link

cetricokola commented Jul 2, 2021 via email

@silva-thiago
Copy link

silva-thiago commented Aug 3, 2021

This didn't work for me, but I found another solution that did.

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

PATH="$HOME/.npm/bin:$PATH"
PATH="./node_modules/.bin:$PATH"

I just added the lines that didn't exist in my ~/.zshrc file.

@pa1codehub
Copy link

pa1codehub commented Sep 21, 2022

I have created a directory for global installations in the $HOME directory instead of using sudo for the installations in the /usr. Below are the steps I followed and installed gulp but seeing command not found in the VS code project. Can someone please let me know what is the issue here?
`Make a directory for global installations in the $HOME directory,
mkdir ~/.npm-global

Configure npm to use the new directory path,
npm config set prefix '~/.npm-global'

Open or create a /.zsh_profile file and add this line,
export PATH=
/.npm-global/bin:$PATH

Back on the command line, update your system variables,
source ~/.zsh_profile`

@pa1codehub
Copy link

I have created a directory for global installations in the $HOME directory instead of using sudo for the installations in the /usr. Below are the steps I followed and installed gulp but seeing command not found in the VS code project. Can someone please let me know what is the issue here? `Make a directory for global installations in the $HOME directory, mkdir ~/.npm-global

Configure npm to use the new directory path, npm config set prefix '~/.npm-global'

Open or create a /.zsh_profile file and add this line, export PATH=/.npm-global/bin:$PATH

Back on the command line, update your system variables, source ~/.zsh_profile`

I resolved it. I was updating the incorrect file - the path should be updated in ~/.zshrc file but not ~/.zsh_profile

@Anarqurbanov14
Copy link

Thank you my brother!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment