0

I came from windows to Ubuntu and tried to install laravel following link https://laravel.com/docs/5.0 I ended with the installer 1.4.... I don't recall which one so I decided to use

composer global require "laravel/installer"

I ended with the installer 4.1.1 but if I close the terminal and open it again and run laravel it does not find the command. I found the following command searching for a solution PATH="~/.config/composer/vendor/bin:$PATH" I have to run this each time for the laravel command to work. Is there a permanent solution? I'm new to linux and I'm having so many issues and could not find a solution. I plan to update laravel but I cannot even get this running properly. Is there a better way? and would this affect my current project if I don't run the mentioned command?

1 Answer 1

0

What you're doing when you use PATH="~/.config/composer/vendor/bin:$PATH" from the command line, is temporarily adding that PATH while you are within a session in your terminal. Once you close the terminal, you end the session, the PATH you added is removed along with session, and the terminal forgets all about where Laravel is located.

Permanently add your PATH, using the .profile file

tl;dr
Add this line to your shell's profile file:
export PATH="$HOME/.config/composer/vendor/bin:$PATH"

Each time you open your terminal, it processes a few files to gather information about the environment. In order to permanently let your terminal know about Laravel's location, you will need to add the composer directory to one of these processed files.

  1. Figure out which shell you're using: type echo $0 in your terminal
  2. From the output of this command, determine which shell you're using, and which .profile file it uses:
    • usr/sh: the file is .profile
    • bash: the file is .bash_profile
    • /usr/bin/zsh: the file is .zprofile
    • You might have to figure it out if you're using a different shell. But it's not hard cause most of the files out there follow the same sort of naming, and exist in your HOME directory
  3. Open your shell's .profile file. It should be located in your HOME directory.
  4. Add the following to that file, on it's own line, and then save it.
    • export PATH="$HOME/.config/composer/vendor/bin:$PATH"
    • this is processed every time you open a new terminal, that's how it will now know where to find Laravel
    • you can also use composer to figure out what the path to composer's global config directory is by using this in your profile instead export PATH="$(composer config -g home)/vendor/bin:$PATH"
  5. Restart your terminal and the PATH to Laravel will now be permanently set

Quickest way is to just type this command in your terminal

  1. type echo "export PATH=$(composer config -g home)/vendor/bin:$PATH" >> ~/.profile in your terminal, making sure to swap out .profile for your shell's profile file.
    • The double ">>" appends the output of the echo command (which is just the text in the quoted portion of the command), to the profile file
    • If you use single ">" it will overwrite the entire file with only the echoed PATH, so be careful. The path will still be set if you use single ">", it will just hose anything that existed inside that file.
    • $(composer config -g home) is explained above
  2. Restart your terminal and the PATH to Laravel will now be permanently set

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .