I get "laravel: command not found" on Ubuntu 20.04

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Solving "laravel: command not found" on Ubuntu 20.04: A Deep Dive into PATH and Composer As a senior developer, I’ve seen countless setups where the installation process seems flawless—Apache, PHP, MySQL are all running—but the crucial development tools just refuse to cooperate. The error `command not found` when trying to run something like `laravel -V` is one of the most frustrating roadblocks. It typically signals a problem with how your operating system's shell (Bash) is configured to locate executable files. If you’ve followed standard installation guides and still hit this snag on Ubuntu 20.04, don't worry. This issue is almost always related to environment variables, specifically the `$PATH`. Let’s diagnose why this happens and walk through the definitive steps to fix it. ## Understanding the `$PATH` Environment Variable The `$PATH` variable tells your shell where to look for executable programs when you type a command. When you type `laravel`, the system checks every directory listed in `$PATH` sequentially until it finds an executable file with that name. If the directory where Laravel or Composer places its binaries is not included in this list, the shell throws the "command not found" error, even if the program exists on your system. The output you shared regarding your `$PATH` is the key to understanding the problem: ```bash /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ``` While this path includes many standard system directories, it often misses the specific location where user-installed tools like Composer or framework binaries are placed by default during a fresh installation. ## Step 1: Verifying the Laravel Installation Method The way you install global tools varies depending on whether you use system package managers (like `apt`) or dependency managers (like Composer). For modern PHP development, tools like the Laravel installer are primarily managed via Composer. If you installed Laravel globally using Composer, the executable file is usually placed in a directory within your home folder, such as `~/.composer/vendor/bin` or similar paths configured by Composer. If this path isn't in your `$PATH`, the system won't find it. ## Step 2: The Definitive Fix – Updating Your PATH The solution involves ensuring that the directory containing the executables is correctly added to your shell's search path. We can achieve this by editing your shell configuration file, typically `~/.bashrc`. 1. **Open your configuration file:** Use a text editor like `nano`: ```bash nano ~/.bashrc ``` 2. **Add the necessary export line:** Add the following line to the end of the file. This command ensures that Composer's binary directory is included in your execution path: ```bash export PATH="$PATH:$HOME/.composer/vendor/bin" ``` *Note: If you installed Laravel via a different method, you may need to adjust this path accordingly, but for Composer-managed tools, this is the common fix.* 3. **Save and Exit:** Save the file (Ctrl+O, Enter) and exit (Ctrl+X). 4. **Apply Changes:** For the changes to take effect immediately in your current terminal session, source the file: ```bash source ~/.bashrc ``` ## Step 3: Testing the Command Now, try running the command again. If the setup was correct and you followed these steps, the system should now be able to locate the Laravel executable: ```bash laravel -V ``` If this command successfully returns a version number, congratulations! You have successfully configured your environment to recognize globally installed tools. This foundational step is crucial for any serious work with modern PHP frameworks, especially when managing dependencies as you do with Laravel. For deeper insights into building robust applications, remember that understanding these underlying system mechanics is just as important as mastering the framework itself, much like the principles behind efficient dependency management discussed on platforms like [laravelcompany.com](https://laravelcompany.com). ## Conclusion The `command not found` error is rarely a bug in the application itself; it’s almost always an issue with the environment configuration. By systematically checking and adjusting your `$PATH` variable, you gain control over how your operating system interacts with the tools you install. Always start by inspecting your environment variables before diving into deep code debugging. Happy coding!