Laravel:找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35211862/
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 17:15:25  来源:igfitidea点击:

Laravel: command Not found

laravelcomposer-php

提问by Dallas Caley

I feel like a moron for having to ask this, and I've gone through all the similar questions to no avail. I am running Ubuntu 14.04 in a vagrant vm on a mac. I have composer installed and i have run these commands:

不得不问这个问题,我觉得自己像个白痴,我已经解决了所有类似的问题,但无济于事。我在 Mac 上的 vagrant vm 中运行 Ubuntu 14.04。我已经安装了 Composer 并且我已经运行了这些命令:

composer global require "laravel/installer"

(this appears to have worked and shows that laravel is one of things that was downloaded)

(这似乎有效,并表明 Laravel 是已下载的内容之一)

I have also added this line to the .bashrc

我还将这一行添加到 .bashrc

export PATH="~/.composer/vendor/bin:$PATH"

Note, i added this to both the vagrant user as well as the root users .bashrc file. I have logged out and back into the shell and verified the path with this command:

请注意,我将此添加到 vagrant 用户和 root 用户 .bashrc 文件中。我已经注销并返回到 shell 并使用以下命令验证了路径:

echo $PATH

Which gives me this:

这给了我这个:

~/.composer/vendor/bin:~/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

~/.composer/vendor/bin:~/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr /games:/usr/local/games

and the command itself that fails is this

而失败的命令本身就是这个

laravel new test

I don't see what i could be missing, any ideas?

我不明白我可能会错过什么,有什么想法吗?

回答by phaberest

It is better to use $HOMEinstead of just ~.

最好使用$HOME而不是仅使用~.

In my .zshrc(I use zsh) I have it working this way

在我的.zshrc(我使用zsh)中,我以这种方式工作

export PATH="$PATH:$HOME/.composer/vendor/bin"

Make sure your terminal does actually use .bashrcand not maybe .bash_profile, if that is the case you should edit that file. If you are using it from the VM, the user you log in with when you call vagrant sshis vagrant, not root.

确保您的终端确实使用.bashrc而不是使用.bash_profile,如果是这种情况,您应该编辑该文件。如果您从 VM 使用它,则您在调用时登录的用户vagrant sshvagrant,而不是root

In addition, remember to source the file after the edit, or open a new terminal.

另外,记得在编辑后source文件,或者打开一个新的终端。

UPDATE

更新

I see there are answers that put the $PATHafter composer's path, so I thought I could tell you what I learned to be the difference.

我看到有些答案指出了$PATH后作曲家的道路,所以我想我可以告诉你我学到的不同之处。

It's not a random thing you can put whatever way you want. What you put after overwrites what comes before. You're gonna need to know it if you want to use packages that overwrites anything installed in paths that are already in PATH.

这不是随意的事情,您可以随心所欲地放置。你后面放的会覆盖前面的。如果您想使用覆盖已安装在PATH.

That means that if you have something installed on you system and you install a newer version of the package using composer, it will have the same command to start so if the composer path will not be afterthe system path, you'll have to reference the full path to the binary inside composer's vendor/binto execute it.

这意味着,如果你已经安装了你的系统上的东西,你用作曲家安装包的新版本,它具有相同的命令来启动,所以如果作曲家路径不会是以后的系统路径,你就必须参考Composer 中二进制文件的完整路径vendor/bin来执行它。

回答by Rasel Ahmed

Open your terminal and run these given lines:

打开终端并运行这些给定的行:

For zsh and bash:

对于 zsh 和 bash:

export PATH="$HOME/.config/composer/vendor/bin:$PATH"

source ~/.zshrc
source ~/.bashrc

For bash only:

仅用于 bash:

export PATH=~/.config/composer/vendor/bin:$PATH

source ~/.bashrc

回答by ManiacTwister

If you put the tilde (~) inside quotes it won't be translated to your home directory. Run this and it should work:

如果您将波浪号 (~) 放在引号内,它不会被翻译到您的主目录。运行它,它应该可以工作:

export PATH=~/.composer/vendor/bin":$PATH"

回答by Matt Stephens

For anyone using HomesteadI found this one worked for me

对于任何使用Homestead我的人,我发现这个对我有用

export PATH="$PATH:$HOME/.config/composer/vendor"

回答by joelmez4

paste this

粘贴这个

export PATH=~/.composer/vendor/bin:$PATH

and restart the termminal.

并重启终端。

回答by brucekaushik

Just adding to the accepted answer...

只是添加到接受的答案...

In case you are executing the commands directly on the terminal (in which case the path will remain available till the terminal window or tab closes)

如果您直接在终端上执行命令(在这种情况下,路径将保持可用,直到终端窗口或选项卡关闭)

If you mess up the earlier path, you need to open and close the terminal window (or tab)

如果弄乱了前面的路径,则需要打开和关闭终端窗口(或选项卡)

Example:

例子:

first execute (mess up the path in someway)

首先执行(以某种方式弄乱路径)

PATH="test"

then execute

然后执行

PATH="$PATH:$HOME/.config/composer/vendor/bin"

You will still get the error Now close the terminal window or tab and reopen it and execute

您仍然会收到错误现在关闭终端窗口或选项卡并重新打开它并执行

PATH="$PATH:$HOME/.config/composer/vendor/bin"

And the error should be gone!

错误应该消失了!

回答by mzalazar

Check if /root/.composer directory EXISTS, if does NOT exist then install composer like this:

检查 /root/.composer 目录是否存在,如果不存在,则像这样安装 composer:

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

And install laravel again, after that your command will work.

并再次安装laravel,之后您的命令将起作用。