我已经安装Laravel使用作曲家没有问题,但当我试图在我的终端执行“Laravel”时,我有这个典型的错误:

-bash: laravel:命令未找到

如果我阅读官方网站的文档,我需要这样做:

确保将~/.composer/vendor/bin目录放在PATH中,这样当您在终端中运行laravel命令时,就可以找到laravel可执行文件。

但我不知道该怎么做。

你能帮我一下吗?谢谢! !


当前回答

对于使用Linux和Zsh的用户:

1 -添加这一行到你的。zshrc文件

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

2 -跑

source ~/.zshrc

Linux下“composer”文件夹路径与Mac不同 在Zsh路径中使用$HOME而不是~ .zshrc文件隐藏在Home文件夹中 export PATH=导出带引号的路径,这样Laravel可执行文件就可以被你的系统定位 $PATH是为了避免覆盖系统路径中已经存在的内容

其他回答

终端类型:

 composer global require "laravel/installer"

当作曲家完成时,输入:

vi ~/.bashrc

粘贴并保存:

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

终端类型:

source ~/.bashrc

打开另一个终端窗口,输入:laravel

使用MacBook时,请参考下面的代码片段;

zsh:

echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >>  ~/.zshrc
source ~/.zshrc

Bash的:

echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

如果你是2021年来到这里,这也适用于我使用Ubuntu 16.04

nano ~/.bash_profile 
export PATH=$HOME/.config/composer/vendor/bin:$PATH
ctrl+x and save 
source ~/.bash_profile

如果你使用的是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 command composer 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 command in 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!!

以上步骤适用于我的Ubuntu 16.04

Composer应该全局安装: 在你的终端上运行:

    mv composer.phar /usr/local/bin/composer

现在编写器命令可以工作了。