Reputation: 2100
I'm a newbie when it comes to Linux administration using bash... I was following a tutorial on how to install laravel 5.2 from here... installed it successfully...
firstly I installed composer and ran the following command
composer global require "laravel/installer"
after this put this in my path too in ~/.zshrc
like this
export PATH="~/.composer/vendor/bin:$PATH"
When I run the laravel
command from the terminal I get the following error
➜ ~ laravel
zsh: command not found: laravel
If I echo $PATH
it shows it have added up in the path
Note: I have installed oh my zsh
on my terminal...
What do I have to do to get it working please help
Upvotes: 67
Views: 79551
Reputation: 2975
On macOS and Ubuntu 22.04 with zsh (Oh My ZSH!).
Add Laravel cli with composer :
composer global require laravel/installer
edit : ~/.zshrc
add to file :
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
run:
source ~/.zshrc
Upvotes: 16
Reputation: 321
for MACOS
type on terminal
composer global require laravel/installer
open ~/.zprofile
add this :- export PATH="$HOME/.composer/vendor/bin:$PATH"
Run:- source ~/.zprofile
Upvotes: 1
Reputation: 2501
Make sure that you've PHP and Composer installed on your system:
Open a new terminal shell, navigate to your project's directory and run the following command:
echo -n 'export PATH="$HOME/.composer/vendor/bin:$PATH"' << ~/.zshrc && source ~/.zshrc
If it errors asking for permissions run this:
sudo !!
This will run the previous command with sudo
appended to it.
If your machines using:
laravel@version{5,6,7}.x
, running: shell PHP >= 7.2.5
composer create-project --prefer-dist laravel/laravel demoblog
Alternatively, these instructions may serve you well.
Upvotes: 3
Reputation: 641
Try to do this:
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
Upvotes: 64
Reputation: 5886
I think ZSH won't expand the ~
on PATH
. Try this in your .zshrc
file instead:
export PATH="$HOME/.composer/vendor/bin:$PATH"
Upvotes: 282
Reputation: 117
For Linux:
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
or better still edit the .zshrc file as below
echo "PATH=\"$HOME/.config/composer/vendor/bin:$PATH\"" >> ~/.zshrc
source ~/.zshrc
Upvotes: 1
Reputation: 29
Put this to .zshrc file:
export PATH="$HOME/.composer/vendor/bin:$PATH"
And make sure you run:
source ~/.zshrc
Upvotes: 1
Reputation: 31
I too was getting the same error while creating a new Laravel project using composer but anything mentioned about the path didn't solved it and a simple trick help to resolve this issue.
Try to run this command on the terminal of your project folder :
composer global require laravel/installer
Article from laracasts helped me: https://laracasts.com/discuss/channels/laravel/laravel-command-not-found-by-zsh-on-macos
Upvotes: -1
Reputation: 1776
Try to do this:
macOS:
$HOME/.composer/vendor/bin
Windows:
%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
GNU / Linux Distributions:
$HOME/.config/composer/vendor/bin or $HOME/.composer/vendor/bin
Upvotes: 0
Reputation: 1065
My solution was:
echo "PATH=\"$HOME/.config/composer/vendor/bin:$PATH\"" >> ~/.zshrc
source ~/.zshrc
laravel
More info here 👌
Upvotes: 5
Reputation: 547
When you run command laravel
in your terminal, you call the laravel file inside composer/vendor/bin directory.
If none of the above works, then find where your vendor dir is by running:
composer global about
you will see something like: "Changed current directory to /home/username/.config/composer".
That means that your vendor dir is located in that path. Then add an alias in .zshrc file:
alias laravel="$HOME/.config/composer/vendor/bin/laravel"
.
Now you are pointing to the 'laravel' file in your filesys using the same command as you would normally.
or you can add composer to your path:
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
, which is the recomended way.
Upvotes: 1
Reputation: 412
As a follow up to Chris' answer,
The command export PATH="$HOME/.composer/vendor/bin:$PATH"
will work, but only for your current terminal session.
If you would like the path to always be available when zsh launches, add PATH="$HOME/.composer/vendor/bin:$PATH"
to the bottom of your ~/.zshrc
file. Run the zsh
command or restart your terminal and laravel
will be available in every session you start.
Upvotes: 30
Reputation: 704
I got the same problem on macOS Sierra. Edit your .zshrc file with
PATH=~/.composer/vendor/bin:$PATH
That worked for me.
Upvotes: 10