realph
realph

Reputation: 4671

zsh: command not found: gulp

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!

Upvotes: 26

Views: 41003

Answers (9)

Sumit Kapoor
Sumit Kapoor

Reputation: 1119

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

Upvotes: 1

Cholan Madala
Cholan Madala

Reputation: 305

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

Upvotes: 4

Brad Ahrens
Brad Ahrens

Reputation: 5168

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.

Upvotes: 1

Zaid Haider
Zaid Haider

Reputation: 598

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.

Upvotes: 14

Edward
Edward

Reputation: 21

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"

Upvotes: 2

sAguinaga
sAguinaga

Reputation: 659

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

Upvotes: -1

Darryl Mendonez
Darryl Mendonez

Reputation: 1161

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

Upvotes: 34

Adaephon
Adaephon

Reputation: 18329

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.

Upvotes: 10

Siguza
Siguza

Reputation: 23820

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

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

Upvotes: 4

Related Questions