zsh: command not found laravel
Asked Answered
G

13

61

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

Grappa answered 8/4, 2016 at 22:29 Comment(5)
just do composer create-project laravel/laravel ProjectName --prefer-distNagari
Is there something called laravel in ~/.composer/vendor/bin?Caylacaylor
@Caylacaylor yes there is a file called laravel in ~/.composer/vendor/bin I've checked while i was trying to run the commandGrappa
Then try running it directly: ~/.composer/vendor/bin/laravel and see if that works. If not, make sure it's executable.Caylacaylor
M1 Mac - the below to my .zshrc done the trick for me. REMEMBER to source ~/.zshrc or quit and reopen your terminal for the setting to take effect. export PATH="$HOME/.composer/vendor/bin:$PATH"Porphyritic
I
267

I think ZSH won't expand the ~ on PATH. Try this in your .zshrc file instead:

export PATH="$HOME/.composer/vendor/bin:$PATH"
Irradiation answered 8/4, 2016 at 23:18 Comment(7)
Only works until I close out of the terminal. any ideas?Laius
@PeterGMac. What do you mean? We are taking about the .zshrc file which is executed every time you start a new zsh session (i.e. every time you open a terminal). It only works until you close your terminal in the sense it works from when you open your terminal until you close your terminal?Irradiation
why i have to add this every time i open the terminal?Aweather
This also solved a problem I had with migrations not working with SQLSTATE[HY000] [2002] No such file or directory when using homestead along with mamp pro socket (after setting up unix_socket, right localhost and everything else, also successfully tested connection, still couldn't run migrations) so THANK YOU!Avid
In my case, I had to use different path: export PATH="$HOME/.config/composer/vendor/bin:$PATH"Sherrill
For me also only export PATH="$HOME/.config/composer/vendor/bin:$PATH" works. I'm on ubuntu 19.04Beggary
@PeterGMac. You can add that code to ~/.zshrc, restart terminal and it will work (I'm using Iterm2 with Zsh on Mac)Redress
N
59

Try to do this:

export PATH="$HOME/.config/composer/vendor/bin:$PATH"
Nub answered 15/2, 2017 at 16:0 Comment(5)
This worked for me. I'm on Manjaro using ZSH and oh-my-zshCardiogram
This is the right answer for Ubuntu 22.04 LTSHyponasty
this should be the right answer !Photogrammetry
Thank god! after few hours of searching finally found the answer that works for me.Impend
Working for PopOS linux with Laravel Installer 5.5Olshausen
R
29

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.

Rehnberg answered 21/2, 2018 at 12:42 Comment(1)
You need to run: source ~/.zshrc to make it available in the current session also (without restarting terminal).Alyssaalyssum
D
13

On Ubuntu 20.04 / 22.04 with zsh (Oh My ZSH!) and macOS.

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
Dewayne answered 28/7, 2021 at 10:6 Comment(1)
but macos has ~/.zprofile File for thisWellmeaning
H
10

I got the same problem on macOS Sierra. Edit your .zshrc file with

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

That worked for me.

Hortative answered 29/9, 2017 at 18:37 Comment(0)
C
5

My solution was:

echo "PATH=\"$HOME/.config/composer/vendor/bin:$PATH\"" >> ~/.zshrc
source ~/.zshrc
  • Then type laravel

More info here 👌

Cardiomegaly answered 14/9, 2020 at 2:38 Comment(0)
P
3

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.

Porphyritic answered 5/8, 2020 at 19:41 Comment(0)
G
1

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.

Gandzha answered 5/4, 2020 at 20:28 Comment(0)
G
1

For Linux:
make sure you fully add the path to composer to your system path
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
George answered 21/6, 2021 at 20:18 Comment(0)
N
1

Put this to .zshrc file:

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

And make sure you run:

source ~/.zshrc

Nidifugous answered 6/5, 2022 at 14:21 Comment(0)
R
0

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
Reel answered 11/12, 2020 at 11:24 Comment(0)
W
0

for MACOS

type on terminal

composer global require laravel/installer

open ~/.zprofile

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

Run:- source ~/.zprofile

Wellmeaning answered 19/10, 2023 at 7:2 Comment(0)
S
-1

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

Sherly answered 22/4, 2021 at 0:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.