zsh: command not found: gulp
Asked Answered
D

9

25

I've installed zsh with homebrew and changed my shell to it. I'm having a problem when trying to run the gulp command, which worked before I changed the shell to zsh.

zsh: command not found: gulp

A bit of research leaves me to believe it has something to do with my PATH. My PATH looks like this is my .zshrc file.

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

I want to say I installed node with brew. How can I use gulp with zsh without changing back to the default shell?

Any help is appreciated. Thanks in advance!

Dopey answered 23/4, 2015 at 8:31 Comment(5)
Well, where is the gulp binary? Try whereis gulp in your old shell and see if that path is in your PATH variable.Mccraw
whereis gulp doesn't return anything. But which gulp returns this: /Users/realph/.node/bin/gulp.Dopey
Then add $HOME/.node/bin to your path.Mccraw
@Mccraw To the .zshrc file?Dopey
The answer by @Abdennour provided an easy solution: [Command not found after npm install in zsh ](#12744428)Vortumnus
D
10

There is usually no need - and it is probably a bad idea - to set PATH to a literal value in ~/.zshrc. In doing so, you may remove some directories that have previously been added to PATH.

In your case, as it worked with another shell, I would first try to just remove the line where you set PATH as zsh should inherit PATH from its own parent environment.

If that does not add the path containing gulp (probably because it was previously added in the configuration of your old shell), you can add

PATH=$HOME/.node/bin:$PATH

to your ~/.zshrc.

Note: as PATH is already part of the environment, there is no need to export it again.


Generally, if you want to add something to PATH you can use:

PATH="/something/new/bin:$PATH"

This prepends /something/new/bin to PATH

If you really want to remove something from PATH this should do the trick:

PATH=${${PATH//\/something\/old\/bin/}//::/:}

This removes any occurences of /something/old/bin (slashes need to be escaped) from PATH and then removes duplicate colons.

Dogtired answered 23/4, 2015 at 9:0 Comment(2)
That makes a lot of sense. Thanks! One more question I have is there any reason why I'm having a problem running gulp in zsh. I'm getting this error: events.js:72 throw er; // Unhandled 'error' event.Dopey
Sorry, I cannot help you there. Anyway, it would probably be best, if you opened a new question for that anyway.Dogtired
C
33

I did sudo npm install gulp -g, typed in my password, and after installing it worked for me.

Counteract answered 13/7, 2016 at 20:34 Comment(4)
On MacOS Catalina, this worked for me though with a few adjustments. Using the command as is gave error gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/Users/my_user/Library/Caches/node-gyp". However, running the command locally within the project worked just fine and I was able to use gulpBubo
@JonathanKibet me too getting this error. can you share the command here. thank youMatri
@QadirHussain the command is right on this answer you are commenting on. sudo npm install gulp -gBubo
This command in this answer is actually creating problem. you mentioned a few adjustments what are those adjustments?Matri
G
14

Though this is an old post, but none of the above solutions were working for me (Catalina 10.15.3). So basically issue with me wasn't about installing the gulp but not proper linking.

Commands I ran are:-

  1. npm config set prefix /usr/local

  2. npm link gulp

Hope this help anyone.

Guzzle answered 3/2, 2020 at 7:11 Comment(2)
I use same mac os version and this answer fixed my issue, thanks a lotTransmissible
I am guessing that gulp will not work if you remove the folder where npm link was executed. If so I would not recommend this fix and it is a dirty fix.Thetis
D
10

There is usually no need - and it is probably a bad idea - to set PATH to a literal value in ~/.zshrc. In doing so, you may remove some directories that have previously been added to PATH.

In your case, as it worked with another shell, I would first try to just remove the line where you set PATH as zsh should inherit PATH from its own parent environment.

If that does not add the path containing gulp (probably because it was previously added in the configuration of your old shell), you can add

PATH=$HOME/.node/bin:$PATH

to your ~/.zshrc.

Note: as PATH is already part of the environment, there is no need to export it again.


Generally, if you want to add something to PATH you can use:

PATH="/something/new/bin:$PATH"

This prepends /something/new/bin to PATH

If you really want to remove something from PATH this should do the trick:

PATH=${${PATH//\/something\/old\/bin/}//::/:}

This removes any occurences of /something/old/bin (slashes need to be escaped) from PATH and then removes duplicate colons.

Dogtired answered 23/4, 2015 at 9:0 Comment(2)
That makes a lot of sense. Thanks! One more question I have is there any reason why I'm having a problem running gulp in zsh. I'm getting this error: events.js:72 throw er; // Unhandled 'error' event.Dopey
Sorry, I cannot help you there. Anyway, it would probably be best, if you opened a new question for that anyway.Dogtired
M
4

Add $HOME/.node/bin to your path variable, i.e. add this line to your .zshrc:

export PATH="$HOME/.node/bin:$PATH"
Mccraw answered 23/4, 2015 at 8:43 Comment(2)
Thanks! That works great. Just to be clear, that line of code is adding my node folder to the $PATH variable?Dopey
Yes. Particularly, to the beginning of it, so any binary in your node folder will override binaries in the system folders on your command line.Mccraw
K
4

sudo npm link gulp and giving the password has solved my problem.

Knightly answered 5/10, 2020 at 9:56 Comment(1)
I thin gulp will stop working if you remove the project where npm link was executed. meaning each time you would run in this problem and will have to search for a this fix whenever you remove mentioned folder. Thus I would not suggest this fix.Thetis
V
2

Open .zshrs file and add this:

export PATH="$PATH:$HOME/.rvm/bin"
PATH=$PATH:/usr/local/bin
npm set prefix ~/.npm
PATH="$HOME/.npm/bin:$PATH"
PATH="./node_modules/.bin:$PATH"
Vibrissa answered 15/6, 2019 at 18:7 Comment(0)
E
1

I realize this is an old question, but I came upon this problem recently and a different reason for this error.

At least for me, I inherited a legacy project using Gulp 3.9.1 while I am using node 12.x on my machine.

In this case, I needed to switch to Node 10.0.0, remove package-lock.json and the node_modules, then reinstall the node packages and run gulp.

Steps:

  • Delete package-lock.json, node_modules folder

  • Install NVM (to manage versions of node):

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash

  • Use NVM:

    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

  • Install node 10.0.0 (which will work for Gulp 3.9.1):

    nvm install 10.0.0

  • Use node.js 10.0.0

    nvm use 10.0.0

  • In my case, rebuild node-sass:

    npm rebuild node-sass

  • Then, you can use gulp:

    gulp

Hope this helps someone.

Entrench answered 18/5, 2020 at 9:38 Comment(0)
G
1

When you are installing gulp inside your project folder, To use gulp it needs to be run from the installed path, For that you need to provide the path when installing gulp in your project folder. In one of the answers above it has been given on how to set the path when installing gulp. To fix this issue there is one more way of handling it. you can install gulp globally which will be accessible anywhere from your system, All you have to do it execute the below command:-

npm i --global gulp

here --global is an argument which you give for installing the package globally.

i stands for install

Gamble answered 20/8, 2021 at 4:32 Comment(0)
C
-1

As part of a tool: VivaGraphJS I did this and it worked:

node_modules/.bin/gulp release

and got:

[09:56:05] Using gulpfile ~/KynKon/Sandbox/VivaGraphJS/gulpfile.js
[09:56:05] Starting 'clean'...
[09:56:05] Starting 'build'...
[09:56:06] Finished 'build' after 923 ms
[09:56:06] Finished 'clean' after 1.03 s
[09:56:06] Starting 'release'...
[09:56:06] Finished 'release' after 59 ms
$ npm test
Colorfast answered 11/3, 2018 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.