bash 安装后找不到 Gulp 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25090452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:36:21  来源:igfitidea点击:

Gulp command not found after install

macosbashterminalnpmgulp

提问by iluvpinkerton

I installed gulp(globally) and it looks like it worked because it ran this code:

我安装了 gulp(global) 并且它看起来工作正常,因为它运行了以下代码:

├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

But when I type gulpit says -bash: gulp: command not found

但是当我输入时gulp它说-bash: gulp: command not found

Any idea what's going on?

知道发生了什么吗?

回答by iluvpinkerton

Turns out that npm was installed in the wrong directory so I had to change the “npm config prefix” by running this code:

结果发现 npm 安装在错误的目录中,所以我不得不通过运行以下代码来更改“npm 配置前缀”:

npm config set prefix /usr/local

Then I reinstalled gulp globally (with the -g param) and it worked properly.

然后我全局重新安装了 gulp(使用 -g 参数)并且它正常工作。

This article is where I found the solution: http://webbb.be/blog/command-not-found-node-npm

这篇文章是我找到解决方案的地方:http: //webbb.be/blog/command-not-found-node-npm

回答by thehme

Not sure why the question was down-voted, but I had the same issue and following the blog post recommended solve the issue. One thing I should add is that in my case, once I ran:

不知道为什么这个问题被否决了,但我遇到了同样的问题,并按照推荐的博客文章解决了这个问题。我应该补充的一件事是,就我而言,一旦我跑了:

npm config set prefix /usr/local

I confirmed the npm root -gwas pointing to /usr/local/lib/node_modules/npm, but in order to install gulpin /usr/local/lib/node_modules, I had to use sudo:

我确认了npm root -g被指向/usr/local/lib/node_modules/npm,但为了安装gulp/usr/local/lib/node_modules,我不得不使用sudo

sudo npm install gulp -g

sudo npm install gulp -g

回答by Steve Goldberg

If you're using tcsh(which is my default shell on Mac OS X), you probably just need to type rehashinto the shell just after the install completes:

如果您正在使用tcsh(这是我在 Mac OS X 上的默认 shell),您可能只需要rehash在安装完成后在 shell 中输入:

npm install -g gulp

followed immediately by:

紧随其后的是:

rehash

Otherwise, if this is your very first time installing gulp, your shell may not recognize that there's a new executable installed -- so you either need to start a new shell, or type rehashin the current shell.

否则,如果这是您第一次安装gulp,您的 shell 可能无法识别安装了新的可执行文件——因此您需要启动一个新的 shell,或者输入rehash当前的 shell。

(This is basically a one-time thing for each command you install globally.)

(对于您全局安装的每个命令,这基本上是一次性的。)

回答by sgray

I realize that this is an old thread, but for Future-Me, and posterity, I figured I should add my two-cents around the "running npm as sudo" discussion. Disclaimer: I do not use Windows. These steps have only been proven on non-windows machines, both virtual and physical.

我意识到这是一个旧线程,但是对于 Future-Me 和后代,我想我应该在“以 sudo 方式运行 npm”讨论中添加我的两分钱。免责声明:我不使用 Windows。这些步骤仅在非 Windows 计算机(虚拟和物理)上得到验证。

You can avoid the need to use sudo by changing the permission to npm's default directory.

您可以通过更改 npm 默认目录的权限来避免使用 sudo。



How to: change permissions in order to run npm without sudo

如何:更改权限以便在不使用 npm 的情况下运行 sudo

Step 1: Find out where npm's default directory is.

第 1 步:找出 npm 的默认目录在哪里。

  • To do this, open your terminal and run:
    npm config get prefix
  • 为此,请打开终端并运行:
    npm config get prefix

Step 2: Proceed, based on the output of that command:

第 2 步:根据该命令的输出继续:

  • Scenario One:npm's default directory is /usr/local
    For most users, your output will show that npm's default directory is /usr/local, in which case you can skip to step 4 to update the permissions for the directory.
  • Scenario Two:npm's default directory is /usror /Users/YOURUSERNAME/node_modulesor /Something/Else/FishyLooking
    If you find that npm's default directory is not /usr/local, but is instead something you can't explain or looks fishy, you should go to step 3 to change the default directory for npm, or you risk messing up your permissionson a much larger scale.
  • 场景一:npm 的默认目录是/usr/local
    对于大多数用户,你的输出会显示 npm 的默认目录是 /usr/local,在这种情况下,你可以跳到步骤 4 更新目录的权限。
  • 场景二:npm的默认目录是/usror /Users/YOURUSERNAME/node_modulesor/Something/Else/FishyLooking
    如果你发现npm的默认目录不是/usr/local,而是你无法解释或看起来可疑的东西,你应该去第3步更改npm的默认目录,或者您可能会在更大范围内弄乱您的权限

Step 3: Change npm's default directory:

第 3 步:更改 npm 的默认目录:

  • There are a couple of ways to go about this, including creating a directory specifically for global installations and then adding that directory to your $PATH, but since /usr/local is probably already in your path, I think it's simpler to just change npm's default directory to that. Like so: npm config set prefix /usr/local
    • For more info on the other approaches I mentioned, see the npm docs here.
  • 有几种方法可以解决这个问题,包括专门为全局安装创建一个目录,然后将该目录添加到您的 $PATH,但由于 /usr/local 可能已经在您的路径中,我认为只更改 npm 的路径更简单默认目录到那个。像这样: npm config set prefix /usr/local
    • 有关我提到的其他方法的更多信息,请参阅此处的 npm 文档。

Step 4: Update the permissions on npm's default directory:

第 4 步:更新 npm 默认目录的权限:

  • Once you've verified that npm's default directory is in a sensible location, you can update the permissions on it using the command:
    sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
  • 确认 npm 的默认目录位于合理位置后,您可以使用以下命令更新其权限:
    sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}


Now you should be able to run npm <whatever>without sudo. Note: You may need to restart your terminal in order for these changes to take effect.

现在你应该可以在npm <whatever>没有sudo. 注意:您可能需要重新启动终端才能使这些更改生效。

回答by Atul Kumar

I had similar problem I did the following steps and it worked.Go to mac terminal and execute the commands,

我遇到了类似的问题,我执行了以下步骤并且成功了。转到 mac 终端并执行命令,

1.npm config set prefix /usr/local

1.npm 配置设置前缀 /usr/local

2.sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

2.sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

This two commands will set the npm path right and you no longer have to use sudo in npm. Next uninstall the gulp

这两个命令将正确设置 npm 路径,您不再需要在 npm 中使用 sudo。接下来卸载gulp

  1. npm uninstall gulp

  2. Installl gulp again without sudo, npm install gulp -g

  1. npm 卸载 gulp

  2. 在没有 sudo 的情况下再次安装 gulp,npm install gulp -g

This should work!!

这应该有效!!

回答by Zack Huston

I had this problem with getting "command not found" after install but I was installed into /usr/local as described in the solution above.

我在安装后遇到“找不到命令”的问题,但我已按照上述解决方案中的说明安装到 /usr/local 中。

My problem seemed to be caused by me running the install with sudo. I did the following.

我的问题似乎是由我使用 sudo 运行安装引起的。我做了以下事情。

  1. Removing gulp again with sudo
  2. Changing the owner of /usr/local/lib/node_modules to my user
  3. Installing gulp again without sudo. "npm install gulp -g"
  1. 使用 sudo 再次删除 gulp
  2. 将 /usr/local/lib/node_modules 的所有者更改为我的用户
  3. 在没有 sudo 的情况下再次安装 gulp。“npm 安装 gulp -g”

回答by Sergey Andreev

You need to do this npm install --global gulp. It works for me and i also had this problem. It because you didn't install globally this package.

你需要这样做npm install --global gulp。它对我有用,我也遇到了这个问题。因为你没有全局安装这个包。

回答by Abinet KenoreGetachew

If you are on Mac run use root privilege

如果您在 Mac 上运行,请使用 root 权限

sudo npm install gulp-cli --global

sudo npm install gulp-cli --global

To check if it's installed run

要检查它是否已安装运行

gulp -v

CLI version: 2.2.0 (The output)

CLI 版本:2.2.0(输出)

Local version: Unknown

本地版本:未知

回答by Altair

If you want to leave your prefix intact, just export it's bin dir to your PATH variable:
export PATH=$HOME/your-path/bin:$PATH
I added this line to my $HOME/.profile and sourced it.

如果你想保持你的前缀不变,只需将它的 bin dir 导出到你的 PATH 变量:
export PATH=$HOME/your-path/bin:$PATH
我将此行添加到我的 $HOME/.profile 并获取它。

Setting prefix to /usr/localmakes you use sudo, so I like to have it in my user dir. You can check your prefix with npm prefix -g.

将前缀设置为/usr/local使您使用sudo,所以我喜欢将它放在我的用户目录中。您可以使用npm prefix -g.

回答by Tony Lisanti

I got this working on Win10 using a combination of the answers from above and elsewhere. Posting here for others and future me.

我使用上面和其他地方的答案组合在 Win10 上进行了这项工作。在这里发布给其他人和未来的我。

I followed the instructions from here: https://gulpjs.com/docs/en/getting-started/quick-startbut on the last step after typing gulp --version I got the message -bash: gulp: command not found

我按照这里的说明操作:https: //gulpjs.com/docs/en/getting-started/quick-start但在输入 gulp --version 后的最后一步我收到消息 -bash: gulp: command not found

To fix this:

要解决此问题:

  1. I added %AppData%\npm to my Path environment variable
  2. Closed all gitbash (cmd, powershell, etc...) and restarted gitbash.
  3. Then gulp --version worked
  1. 我将 %AppData%\npm 添加到我的 Path 环境变量中
  2. 关闭所有 gitbash(cmd、powershell 等)并重新启动 gitbash。
  3. 然后 gulp --version 起作用了

Also, found the below for reasons why not to install gulp globally and how to remove it (not sure if this is advisable though):

另外,找到以下原因为什么不全局安装 gulp 以及如何删除它(但不确定这是否可取):

what does gulp-"cli" stands for?

gulp-“cli”代表什么?

How to uninstall Gulp CLI from NPM globally?

如何从 NPM 全局卸载 Gulp CLI?