21

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!

realph
  • 4,481
  • 13
  • 49
  • 104
  • 1
    Well, where is the `gulp` binary? Try `whereis gulp` in your old shell and see if that path is in your `PATH` variable. – Siguza Apr 23 '15 at 08:38
  • 1
    `whereis gulp` doesn't return anything. But `which gulp` returns this: `/Users/realph/.node/bin/gulp`. – realph Apr 23 '15 at 08:39
  • 1
    Then add `$HOME/.node/bin` to your path. – Siguza Apr 23 '15 at 08:40
  • @Siguza To the `.zshrc` file? – realph Apr 23 '15 at 08:41
  • The answer by @Abdennour provided an easy solution: [Command not found after npm install in zsh ](https://stackoverflow.com/questions/12743928/command-not-found-after-npm-install-in-zsh/40375497) – sandraqu Dec 19 '19 at 16:22

9 Answers9

32

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

Darryl Mendonez
  • 1,081
  • 1
  • 15
  • 27
  • 1
    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 `gulp` – Jonathan Kibet Feb 21 '20 at 14:01
  • @JonathanKibet me too getting this error. can you share the command here. thank you – Qadir Hussain Jun 28 '21 at 06:54
  • @QadirHussain the command is right on **this** answer you are commenting on. `sudo npm install gulp -g` – Jonathan Kibet Jun 28 '21 at 10:18
  • 1
    This command in this answer is actually creating problem. you mentioned a few adjustments what are those adjustments? – Qadir Hussain Jun 28 '21 at 11:00
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.

Zaid Haider
  • 530
  • 6
  • 11
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.

Adaephon
  • 16,929
  • 1
  • 54
  • 71
  • 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`. – realph Apr 23 '15 at 12:13
  • 1
    Sorry, I cannot help you there. Anyway, it would probably be best, if you opened a new question for that anyway. – Adaephon Apr 23 '15 at 13:00
4

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

export PATH="$HOME/.node/bin:$PATH"
Siguza
  • 21,155
  • 6
  • 52
  • 89
  • Thanks! That works great. Just to be clear, that line of code is adding my node folder to the `$PATH` variable? – realph Apr 23 '15 at 08:47
  • 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. – Siguza Apr 23 '15 at 08:50
3

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

Cholan Madala
  • 165
  • 1
  • 2
  • 9
  • 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. – Matiss Nov 25 '20 at 13:15
1

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"
Edward
  • 11
  • 2
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.

Brad Ahrens
  • 4,864
  • 5
  • 36
  • 47
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

Sumit Kapoor
  • 1,089
  • 12
  • 10
-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
sAguinaga
  • 638
  • 13
  • 31