[php] Laravel PHP Command Not Found

I have installed Laravel using composer without problems, but when I try to execute "laravel" in my terminal I have this typical error:

-bash: laravel: command not found

If I read the documentation of the official site I need to do that:

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.

But I don't know how to do (I'm new on terminal console commands).

Can you help me with that? Thanks!!

This question is related to php bash laravel

The answer is


1) First, download the Laravel installer using Composer:

composer global require "laravel/installer"

2) Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable can be located by your system.

  set PATH=%PATH%;%USERPROFILE%\AppData\Roaming\Composer\vendor\bin

  eg: “C:\Users\\AppData\Roaming\Composer\vendor\bin” 

3) Once installed, the simple laravel new command will create a fresh Laravel installation in the directory you specify.

eG:  laravel new blog

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" 

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


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


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

When using MacBook, refer to the snippets below;

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

If on mac (and think *nix) just run this in your terminal.

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

Just use it:

composer create-project --prefer-dist laravel/laravel youprojectname

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

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


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.


Solution on link http://tutsnare.com/laravel-command-not-found-ubuntu-mac/

In 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

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


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

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


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

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

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

Now composer commands will work.


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

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

composer global require "laravel/installer=~1.1"

Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to bash

Comparing a variable with a string python not working when redirecting from bash script Zipping a file in bash fails How do I prevent Conda from activating the base environment by default? Get first line of a shell command's output Fixing a systemd service 203/EXEC failure (no such file or directory) /bin/sh: apt-get: not found VSCode Change Default Terminal Run bash command on jenkins pipeline How to check if the docker engine and a docker container are running? How to switch Python versions in Terminal?

Examples related to laravel

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration Target class controller does not exist - Laravel 8 Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required How can I run specific migration in laravel Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory