laravelmacos

zsh: command not found: laravel - How to fix


The issue of installing laravel for the first time using a composer like this :

composer global require laravel/installer

then after you get the success messages and you be happy to run be a normal human and open a new tab and run :

laravel

in a new menu you will get this error in the title :

zsh: command not found: laravel

Solution

  • This because the composer bin directory is not a part of the system path and this is always happening I have never seen someone not getting this error and spending hours trying to fix it.

    Anyway, this means that you will need to go to your composer directory like that:

    ~/.composer/vendor/bin/laravel 
    

    this way, you will find it but it is not convenient always.

    So you will need to add this to your path: ~/.composer/vendor/bin/

    if you cd there and maybe use the full path like this :

    cd ~/.composer/vendor/bin/ then pwd and use the full path rather than the shorthand one.

    it should look something like this : /Users/someName/.composer/vendor/bin

    now copy the path. I will be adding it to the path file using vim :

    So while you are in the bin directory :

    we write: sudo vim /etc/paths remember there is a space after the world vim Now the vim editor will open with the current paths, to insert the new path click letter i and past the full path there ( /Users/someName/.composer/vendor/bin )

    Once you're done, press the escape key Esc to get out of insert mode and back to command mode.

    Type :wq to save and exit your file.

    Now if you open a brand new tab in the terminal you should have access to laravel