If you’re developing Laravel applications, you’re very likely to use a local development installation. Installing Laravel is not very simple, especially if you’re not familiar with composer or with the command line. In this tutorial, I’ll show you a simple way that will most likely fix the problem.
For this tutorial, I’ll assume that you’ve already got Composer installed (globally).
Before starting, you should determine whether you’re using
zsh as a command line shell. If you’ve got no idea what this is, don’t worry 😉. If you’re using a recent macOS, macOS Catalina or later,
zsh is the default. If you want to check if your Mac is using
zsh, open terminal and type one or both of these commands:
One of the commands, the active one, will return a version number (something like
5.8). The inactive one will return an empty line.
How to fix the Laravel command not found for zsh (macOS Catalina and newer)
To allow the use of commands starting with ‘
laravel‘, you’ll need to edit your
.zshrc file. This file should be in your home folder.
First, check whether the file exists:
open -e ~/.zshrc # If you get an error, open up text editor and create # an empty file called '.zshrc' in your home folder.
Next, add the following code at the bottom of your
Save the file. The changes will now be implemented on any new terminal session. Stop the current session or run the code below, and then it will work for the current session too:
How to fix the Laravel command not found for bash (macOS Mojave and older)
We need to do something very similar for
bash as for
zsh. This time, we’ll edit the
.bashrc file. Open it (or create it, if needed), manually or via terminal:
Now add the following line at the end of the file:
Here, too, the changes will only apply for a new session. So stop the current session or run the below code:
Why did we do this?
Laravel is installed via Composer. If you type a command like ‘
laravel‘, you are referencing an executable called
laravel. The command line has a variable somewhere (called
$PATH), where you can add directories to look for executables. If you put an executable in one of the directories in the
$PATH, you do not need to set the path to the executable / script, but you can run it by its name as a command.
Thus, if you run a command for an executable in a folder that’s not in your
$PATH, you’ll get a command not found message. So, we need to add the path to this directory.
I hope this has been helpful for you. Let me know in the comments if it worked for your