228

I installed Laravel using Composer without problems, but when I try to run laravel in the terminal, I get the following error:

-bash: laravel: command not found

The docs say that I need to do the following:

Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable is found when you run the laravel command in your terminal.

How can I do that?

Mehdi Charife
  • 722
  • 1
  • 7
  • 22
chemitaxis
  • 13,889
  • 17
  • 74
  • 125
  • What is your PATH variable value? – Raptor Oct 15 '14 at 07:11
  • How can I obtain that? With echo $PATH? – chemitaxis Oct 15 '14 at 07:12
  • 1
    type `echo $PATH` in Terminal / bash , etc. – Raptor Oct 15 '14 at 07:14
  • /Users/chema/google-cloud-sdk/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Eclipse/sdk/platform-tools:/Applications/Eclipse/sdk/tools – chemitaxis Oct 15 '14 at 07:15
  • 2
    Possible duplicate of [Laravel installation: How to place the ~/.composer/vendor/bin directory in your PATH?](https://stackoverflow.com/questions/25373188/laravel-installation-how-to-place-the-composer-vendor-bin-directory-in-your) – MrTux Feb 12 '18 at 14:27

19 Answers19

367

Ok, I did that and it works:

nano ~/.bash_profile 

And paste

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

do source ~/.bash_profile and enjoy ;)

Important: If you want to know the difference between bash_profile and bashrc please check this link

Note: For Ubuntu 16.04 running laravel 5.1, the path is: ~/.config/composer/vendor/bin

On other platforms: To check where your Composer global directory is, run composer global about. Add /vendor/bin to the directory that gets listed after "Changed current directory to ..." to get the path you should add to your PATH.

D Malan
  • 10,272
  • 3
  • 25
  • 50
chemitaxis
  • 13,889
  • 17
  • 74
  • 125
257

Add the following to .bashrc file (not .bash_profile).

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

at the end of the file and then in terminal run source ~/.bashrc

To verify that:

echo $PATH

(Restart the terminal, Check & Confirm the path is there)

Run the laravel command!

Note: For Ubuntu 16 and above use below:

export PATH="~/.config/composer/vendor/bin:$PATH" 
R T
  • 4,369
  • 3
  • 38
  • 49
  • You can find more information about the differences between these hidden files: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html – chemitaxis Jan 10 '17 at 21:32
  • 1
    late reply. hope it helps someone. check this https://apple.stackexchange.com/questions/42537/why-must-i-source-bashrc-every-time-i-open-terminal-for-aliases-to-work. if you use .bahrc you need to reload every time. so add that in .bash_profile – Sibiraj May 09 '17 at 18:47
  • 1
    I had to add ~/.config to the path.. depends on where the binary is – f_i Nov 25 '17 at 14:13
  • 4
    It might be the '/root/.config/composer/vendor/bin' for linux distros – cagcak Feb 20 '18 at 17:32
  • 3
    `export PATH="~/.config/composer/vendor/bin:$PATH" ` - the life saver on Ubuntu 18.04! :) – Subrata Sarkar Mar 23 '21 at 14:13
  • even after that i still get the same error, any idea on what to do? i have installed laravel as shown here: https://snipboard.io/BpvM8s.jpg and added the PATH as shown here: https://snipboard.io/7zy6qJ.jpg – Yanis Sep 28 '22 at 08:02
  • did you close the terminal and opened again to check the same? – R T Sep 29 '22 at 09:05
  • This `export PATH="~/.config/composer/vendor/bin:$PATH" ` worked for me in Ubuntu 22 – Mayank Dudakiya May 13 '23 at 08:31
108

When using MacBook, refer to the snippets below;

For fish:

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

For zsh:

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

For Bash:

echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Jobseeker
  • 17
  • 6
Chweng Mega
  • 1,598
  • 1
  • 13
  • 22
88

Solution in link. In the 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
Mehdi Charife
  • 722
  • 1
  • 7
  • 22
gilcierweb
  • 2,598
  • 1
  • 16
  • 15
  • Thanks, I was missing the alias on my virtual machine, adding the folder to the PATH didn't help for some reason. – parrker9 Jun 10 '16 at 03:13
  • 1
    you can use ``composer global require "laravel/installer" `` too – TuGordoBello Aug 08 '16 at 02:18
  • In Homestead I needed to set the laravel alias folder to this one instead `/home/vagrant/.config/composer/vendor /bin/laravel` – lucgenti Aug 25 '16 at 10:43
  • 2
    Ubuntu 16.04. I also added the alias at ~/.bashrc `alias laravel='~/.config/composer/vendor/bin/laravel'` – Matiss Dec 29 '16 at 20:09
  • This works for me. Exporting the path to `~/.profile` does not do it. That step with `~/.bashrc` is necessary. – J. Doe Oct 03 '18 at 06:03
  • In Ubuntu 20.04 just adding `alias laravel='~/.composer/vendor/bin/laravel'` was enough – YTZ Oct 05 '20 at 23:26
43

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

MuriloReinert
  • 531
  • 4
  • 3
40

If you're using Ubuntu 16.04.

  1. 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"

  2. 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/

  3. 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'

  4. Now refresh your bashrc using source ~/.bashrc and then laravel is ready!!

above steps works with me in Ubuntu 16.04

Gujarat Santana
  • 9,854
  • 17
  • 53
  • 75
22

For zsh and bash:

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

source ~/.zshrc
source ~/.bashrc

For bash only:

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

source ~/.bashrc
clemens
  • 16,716
  • 11
  • 50
  • 65
Md Rasel Ahmed
  • 1,025
  • 9
  • 12
18

For Developers use zsh Add the following to .zshrc file

vi ~/.zshrc or 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.

source ~/.zshrc

Done! try command laravel you will see.

Sophy
  • 8,845
  • 6
  • 36
  • 30
11

If you are on macOS or *nix just run this in your terminal:

export PATH="$HOME/.composer/vendor/bin:$PATH"
tom
  • 21,844
  • 6
  • 43
  • 36
Shubham A.
  • 2,446
  • 4
  • 36
  • 68
7

For those using Linux with Zsh:

1 - Add this line to your .zshrc file

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

2 - Run

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
guizo
  • 2,594
  • 19
  • 26
7

If you are coming here 2021 this has worked for me also using Ubuntu 16.04

nano ~/.bash_profile 
export PATH=$HOME/.config/composer/vendor/bin:$PATH
ctrl+x and save 
source ~/.bash_profile
Ahmed Magdy
  • 1,054
  • 11
  • 16
4

I set the PATH,but it didn't work.I find other way to solve it. (OSX 10.10 & laravel 5.2)
1) find the executable file:

~/.composer/vendor/laravel/installer/laravel 

2) give execute permissions:

chmod +x ~/.composer/vendor/laravel/installer/laravel 

3) make a soft link to /usr/bin:

sudo ln -s /Users/zhao/.composer/vendor/laravel/installer/laravel /usr/bin/laravel
MD Ashik
  • 9,117
  • 10
  • 52
  • 59
zhaolion
  • 41
  • 2
4

For MAC users:

1. Open terminal

cd ~

2. Double check the $PATH

echo $PATH

3. Edit file

nano ~/.bash_profile

4. PASTE

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

Don't forget to put quotation marks.

5. control + X (y + enter to save the file and exit)

Now start vagrant, go to your folder and try:

laravel new yourprojectname
Đorđe Nilović
  • 3,600
  • 1
  • 25
  • 20
3

type on terminal:

nano ~/.bash_profile 

then paste:

export PATH="/Users/yourusername/.composer/vendor/bin:$PATH"

then save (press ctrl+c, press Y, press enter)

now you are ready to use "laravel" on your terminal

Maii T
  • 31
  • 1
1

If you have Composer installed globally, you can install the Laravel installer tool using command below:

composer global require "laravel/installer=~1.1"
Ian Pinto
  • 2,199
  • 1
  • 21
  • 24
0

Late answer...

Composer 1.10.1 2020-03-13 20:34:27 laravel --version Laravel Installer 3.0.1

Put export PATH=$PATH:~/.config/composer/vendor/bin:$PATH in your ~/.zshrc or ~/.bashrc source ~/.zshrc or ~/.bashrc This works

0

Composer should be installed globally: Run this in your terminal:

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

Now composer commands will work.

Yeshi
  • 177
  • 1
  • 9
-1

My quick way of creating a new project

//install composer locally on web root - run the code from: https://getcomposer.org/download/

Then install laravel:

php composer.phar require laravel/installer

Then create the project without adding anything to any path

vendor/laravel/installer/bin/laravel new [ProjectName]

//add project to git

cd ProjectName
git init
git remote add origin git@...[youGitPathToProject]

Wondering if this way of doing it has any issues - please let me know

alex toader
  • 2,300
  • 1
  • 17
  • 20
-3

Just use it:

composer create-project --prefer-dist laravel/laravel youprojectname
Dharman
  • 30,962
  • 25
  • 85
  • 135
Amir Kaftari
  • 1,305
  • 14
  • 13