How To Add Laravel Directory To Your PATH file

Installing Laravel is a simple setup, but it seems like a lot of simple things also go wrong and if you don’t know how to handle them it can get quite difficult to figure out what is the cause and how to fix it. One of the most common errors you are going to come across is “Laravel: command not found”. There is no need to worry! This error is common even if you have installed everything correctly. Nothing is actually wrong just a small quick fix.

On the official tutorial for Laravel, you will come across the following message that throws quite a few people off.
“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.” This means place the location of Laravel to your PATH file so that you can use the Laravel command. If you don’t do this you will see the following when you run a Laravel command.

Laravel --version
-bash: Laravel: command not found

I’m going to assume that you have used composer to install Laravel. If not then you will need to update the path below to the location of Laravel on your system. Everything else will remain the same. So the issue here is that the PATH file does not know where Laravel is installed. All you have to do is update PATH so that it knows where Laravel is.

I’m going to break this down a bit just in case you haven’t used composer to install Laravel. $PATH: contains the current contents of the PATH file. This is required so you don’t overwrite the current contents of the PATH. The content after PATH is the location of Laravel. If you use composer it is most likely installed in your users directory. e.g. “/root/.composer/vendor/bin”. You can change the directory to whatever directory you have Laravel installed to. The code below should work if you installed Laravel with composer.

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

You should now be able to use Laravel commands regardless of your working directory. To test if this is working, retry the following command.

Laravel --version
Laravel Installer version 1.1


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Can you elaborate a bit more in cases where people installed Laravel without a composer? Thank you in advance