找不到 Laravel PHP 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26376516/
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
Laravel PHP Command Not Found
提问by chemitaxis
I have installed Laravel using composer without problems, but when I try to execute "laravel" in my terminal I have this typical error:
我已经使用 composer 安装了 Laravel 没有问题,但是当我尝试在我的终端中执行“ laravel”时,我遇到了这个典型的错误:
-bash: laravel: command not found
-bash: laravel: 命令未找到
If I read the documentation of the official site I need to do that:
如果我阅读了官方网站的文档,我需要这样做:
Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable is found when you run the laravelcommand in your terminal.
确保将 ~/.composer/vendor/bin 目录放在 PATH 中,以便在终端中运行laravel命令时找到 laravel 可执行文件。
But I don't know how to do (I'm new on terminal console commands).
但我不知道该怎么做(我是终端控制台命令的新手)。
Can you help me with that? Thanks!!
你能帮我解决这个问题吗?谢谢!!
回答by chemitaxis
Ok, I did that and it works:
好的,我这样做了,并且有效:
nano ~/.bash_profile
And paste
并粘贴
export PATH=~/.composer/vendor/bin:$PATH
do source ~/.bash_profile
and enjoy ;)
做source ~/.bash_profile
和享受;)
Important: If you want to know the difference between bash_profileand bashrcplease check this link
重要提示:如果您想知道bash_profile和bashrc之间的区别,请查看此链接
Note:For Ubuntu 16.04 running laravel 5.1, the path is: ~/.config/composer/vendor/bin
注意:对于运行 laravel 5.1 的 Ubuntu 16.04,路径为:~/.config/composer/vendor/bin
回答by R T
Add the following to .bashrc
file (not .bash_profile
).
将以下内容添加到.bashrc
文件(不是.bash_profile
)。
export PATH="~/.composer/vendor/bin:$PATH"
At the end of the file and then in terminal
在文件末尾,然后在终端
source ~/.bashrc
To verify that:
要验证:
echo $PATH
(Restart the terminal, Check & Confirm the path is there)
echo $PATH
(重启终端,检查并确认路径在那里)
Run the laravel command!
运行 laravel 命令!
回答by gilcierweb
Solution on link http://tutsnare.com/laravel-command-not-found-ubuntu-mac/
链接http://tutsnare.com/laravel-command-not-found-ubuntu-mac/ 上的解决方案
In terminal
在终端
# download installer
composer global require "laravel/installer=~1.1"
#setting up path
export PATH="~/.composer/vendor/bin:$PATH"
# check laravel command
laravel
# download installer
composer global require "laravel/installer=~1.1"
nano ~/.bashrc
#add
alias laravel='~/.composer/vendor/bin/laravel'
source ~/.bashrc
laravel
# going to html dir to create project there
cd /var/www/html/
# install project in blog dir.
laravel new blog
回答by Chweng Mega
When using MacBook, refer to the snippets below;
使用 MacBook 时,请参考以下片段;
For zsh:
对于 zsh:
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
For Bash:
对于 Bash:
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
回答by Gujarat Santana
If you're using Ubuntu 16.04.
如果您使用的是 Ubuntu 16.04。
You need to find the composer config files in my case is :
~/.config/composer
or in other cases~/.composer/
you can see the dir after this commandcomposer global require "laravel/installer"
after Laravel Installed you can find your laravel in
~/.config/composer/vendor/laravel/installer/
.
and you will find the Laravel shortcut commandin here :~/.config/composer/vendor/bin/
set your .bashrc using
nano ~/.bashrc
and export your composer config file :export PATH="$PATH:$HOME/.config/composer/vendor/bin"
or you can use allias. but above solution is recommended.alias laravel='~/.config/composer/vendor/laravel/installer/laravel'
Now refresh your bashrc using
source ~/.bashrc
and then laravel is ready!!
在我的情况下,您需要找到 Composer 配置文件:
~/.config/composer
或者在其他情况下,~/.composer/
您可以在此命令后看到目录composer global require "laravel/installer"
安装 Laravel 后,您可以在
~/.config/composer/vendor/laravel/installer/
.
你会在这里找到Laravel 快捷命令:~/.config/composer/vendor/bin/
使用
nano ~/.bashrc
并导出您的作曲家配置文件设置您的 .bashrc :export PATH="$PATH:$HOME/.config/composer/vendor/bin"
或者您可以使用别名。但建议使用上述解决方案。alias laravel='~/.config/composer/vendor/laravel/installer/laravel'
现在使用刷新你的 bashrc
source ~/.bashrc
然后 laravel 准备好了!!
above steps works with me in Ubuntu 16.04
以上步骤适用于 Ubuntu 16.04
回答by MuriloReinert
Type on terminal:
在终端输入:
composer global require "laravel/installer"
When composer finish, type:
当作曲家完成时,输入:
vi ~/.bashrc
Paste and save:
粘贴并保存:
export PATH="~/.config/composer/vendor/bin:$PATH"
Type on terminal:
在终端输入:
source ~/.bashrc
Open another terminal window and type: laravel
打开另一个终端窗口并输入:laravel
回答by Rasel Ahmed
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 Sophy
For Developers use zsh
Add the following to .zshrc
file
对于开发人员使用zsh
将以下内容添加到.zshrc
文件
vi ~/.zshrc
or nano ~/.zshrc
vi ~/.zshrc
或者 nano ~/.zshrc
export PATH="$HOME/.composer/vendor/bin:$PATH"
at the end of the file.
在文件的末尾。
zsh
doesn't know ~
so instead it by use $HOME
.
zsh
不知道~
,而是通过使用它$HOME
。
source ~/.zshrc
source ~/.zshrc
Done! try command laravel
you will see.
完毕!laravel
你会看到try 命令。
回答by guizo
For those using Linux with Zsh:
对于那些使用 Linux 和 Zsh 的人:
1 - Add this line to your .zshrc
file
1 - 将此行添加到您的.zshrc
文件中
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
2 - Run
2 - 运行
source ~/.zshrc
- Linux path to composer folder is different from Mac
- Use
$HOME
instead of~
inside the path with Zsh - The
.zshrc
file is hidden in the Home folder export PATH=
exports the path in quotes so that the Laravel executable can be located by your system- The :$PATH is to avoid overriding what was already in the system path
- Composer 文件夹的 Linux 路径与 Mac 不同
- 使用Zsh
$HOME
代替~
路径内部 - 该
.zshrc
文件隐藏在主文件夹中 export PATH=
用引号导出路径,以便您的系统可以找到 Laravel 可执行文件- :$PATH 是为了避免覆盖系统路径中已有的内容
回答by Shubham A.
If on mac (and think *nix) just run this in your terminal.
如果在 mac 上(并考虑 *nix),只需在您的终端中运行它。
export PATH="~/.composer/vendor/bin:$PATH"