How to make laravel run automatically each time I open a new terminal?
I came from windows to Ubuntu and tried to install laravel following link 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
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.
- Figure out which shell you're using: type
echo $0in your terminal - 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
- usr/sh: the file is
- Open your shell's .profile file. It should be located in your HOME directory.
- Find your HOME directory: type
echo $HOMEin your terminal
- Find your HOME directory: type
- 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"
- Restart your terminal and the PATH to Laravel will now be permanently set
Quickest way is to just type this command in your terminal
- type
echo "export PATH=$(composer config -g home)/vendor/bin:$PATH" >> ~/.profilein 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
- Restart your terminal and the PATH to Laravel will now be permanently set