zsh

How to Fix zsh: command not found: laravel Error in Zsh?

Laravel is a powerful open-source PHP framework used for creating robust and feature-rich websites. It is best known for its powerful features, elegant syntax, active community support, and a vast majority of packages and provides a way to organize your application code and makes it easy to test.

While using this framework on Zsh, you may encounter the “zsh: command not found: laravel” error that could be frustrating for you. After the occurrence of this error, you will not be allowed to use commands related to Laravel in Zsh.

Read this tutorial to learn how to fix the issue and continue working with Laravel-related commands on your Zsh.

How to Fix zsh: command not found: laravel Error in Zsh?

If you are using Zsh on your MacOS and execute psql related commands, you will encounter the following error on the terminal.

The “zsh: command not found: laravel” occurs mainly in Zsh on Mac OS due to missing and misconfigured package installation. Since by default, Laravel isn’t installed on most systems, including MacOS, you should ensure it is installed on your system.

There are multiple ways to install Laravel on Mac OS, but the easiest one you can follow is first to install it through Composer using the following steps:

Step 1: Install Composer on your MacOS system from here.

Note: Ensure running all the commands for the “Download Composer” section in this guide.

Step 2: Then use the command given below to install Laravel from the Composer in Zsh on your macOS system.

 composer global require "laravel/installer"

Step 3: You must change the ownership of the .composer directory to the current user. This step is necessary because the composer command cannot access the directory if it is owned by the root.

sudo chown -R $USER .composer/

Step 4: Then add the composer command to the system path. This means that you will be able to run the composer command from anywhere in your terminal.

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

Step 5: Finally, load the ~/.zshrc file into the current shell to save the changes made in Step 4.

source ~/.zshrc

Once this is done, you can run the laravel command to ensure the error is fixed.

laravel

Conclusion

Laravel is a powerful PHP framework used to create robust and feature-rich websites. However, sometimes, you may experience an error that is a command not found:laravel which occurs due to missing or misconfigured Laravel installation or an incorrect PATH configuration. You can fix this error by installing Laravel on your Mac system in Zsh and setting the Path variable to complete its installation. Once done, you can then use the laravel-related commands again in your Zsh and streamline your website-building tasks.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.