skip to Main Content

I did a fresh install of Ubuntu 20.04 LTS (Focal Fossa), installed Apache, PHP, MySQL and PHP Composer seemingly without issue. However, I still cannot get laravel -V to give me a version number.

I have looked at a multitude of YouTube videos and tried my interpretation of the recommendations found here on Stack Overflow. How can I fix it?

Here’s the output on my shell $PATH.

3

Answers


  1. You must add PHP Composer binaries folder to your $PATH if you’d like to call the binaries globally.


    A) Make sure you have the latest Laravel installer:

    composer global require laravel/installer

    B) Add composer bin folder to your $PATH:

    1. Edit your .bashrc file: gedit $HOME/.bashrc

    2. Add the following line: export PATH="$PATH:$HOME/.config/composer/vendor/bin"

    C) Use the source command to force Ubuntu to reload your .bashrc file:

    source $HOME/.bashrc

    D) Try to output Laravel installer’s version:

    laravel -V


    Additional explanations as requested:

    To execute a command from the Linux terminal, you need to tell Linux where the program is located.

    For example, you could have launched Laravel installer using the full path: $HOME/.config/composer/vendor/bin/laravel -V

    But instead, you wanted to be able to call the laravel -V command directly because you don’t want to type the full path every time.

    Since you are on Ubuntu, the default shell program is Bash. You need to tell Bash where to look when you type a command. In this case, you want Bash to look in the $HOME/.config/composer/vendor/bin/ folder.

    The configuration file for Bash is a hidden file called .bashrc located in the user home folder. Bash stores the list of special folders in a variable called $PATH. To add a new folder, we simply added it to the $PATH variable.

    If you type echo $PATH in your terminal, Bash will output the content of the $PATH variable and you will see a list of folders.

    Now you may ask: "Why did I have to do this? I usually don’t have to mess with my Bash configuration". Yes, this is because you usually install Ubuntu packages and they are configured to work out of the box. In this case, you installed a composer package in your home directory and it’s therefore up to you to configure it the way you want.

    Login or Signup to reply.
  2. You may need to do source $HOME/.bashrc every time you open u a new terminal windows and then do laravel -v

    Login or Signup to reply.
  3. If you are receiving a "laravel command not found" error when trying to create a new Laravel project on your Ubuntu machine, it is likely that Laravel is not installed on your system, or it is not added to the PATH environment variable.

    To install Laravel on Ubuntu, you can follow these steps:

    Install PHP and its dependencies using the following command:

    sudo apt-get install php php-cli php-mbstring git unzip
    
    
    Install Composer by running:
    
        curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
    
    

    Once Composer is installed, you can install Laravel by running:

    composer global require laravel/installer
    

    Next, add the Laravel executable to your PATH by running the following command:

    echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc && source ~/.bashrc
    

    After completing the above steps, try running the laravel new myproject command again, and it should work without any issues.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search