18

I feel like a moron for having to ask this, and I've gone through all the similar questions to no avail. I am running Ubuntu 14.04 in a vagrant vm on a mac. I have composer installed and i have run these commands:

composer global require "laravel/installer"

(this appears to have worked and shows that laravel is one of things that was downloaded)

I have also added this line to the .bashrc

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

Note, i added this to both the vagrant user as well as the root users .bashrc file. I have logged out and back into the shell and verified the path with this command:

echo $PATH

Which gives me this:

∼/.composer/vendor/bin:∼/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

and the command itself that fails is this

laravel new test

I don't see what i could be missing, any ideas?

4
  • 1
    did you run the commands in the VM? or your machine? I have a similar setup, and run them in my machine Commented Feb 4, 2016 at 22:43
  • I didn't try this but it seems a little odd. not wrong necessarily but it seems as though you have your laravel installer and composer installed on your host machine rather than on the vm. Perhaps this does make sense actually as you could have one version of composer/laravel and several VM's. my question to you is what is your host operating system? not sure if composer will run in Mac OSX Commented Feb 5, 2016 at 23:27
  • yeah, I use OS X El Capitan. Composer runs great in OS X (at least in Lion, Mountain Lion, Mavericks and El Capitan) Commented Feb 7, 2016 at 0:45
  • to solve the problem you need to find the compose config files location. And then fix the export PATH stackoverflow.com/a/41476969/2652524 Commented Jan 5, 2017 at 6:12

7 Answers 7

49

It is better to use $HOME instead of just ~.

In my .zshrc(I use zsh) I have it working this way

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

Make sure your terminal does actually use .bashrc and not maybe .bash_profile, if that is the case you should edit that file. If you are using it from the VM, the user you log in with when you call vagrant ssh is vagrant, not root.

In addition, remember to source the file after the edit, or open a new terminal.

UPDATE

I see there are answers that put the $PATH after composer's path, so I thought I could tell you what I learned to be the difference.

It's not a random thing you can put whatever way you want. What you put after overwrites what comes before. You're gonna need to know it if you want to use packages that overwrites anything installed in paths that are already in PATH.

That means that if you have something installed on your system and you install a newer version of the package using composer, it will have the same command to start so if the composer path will not be after the system path, you'll have to reference the full path to the binary inside composer's vendor/bin to execute it.

Sign up to request clarification or add additional context in comments.

8 Comments

This worked for me. Actually both answers here were correct but i'm giving you the point because i also learned that the .bashrc is not always run. I googled that and found out that it has to be listed in your .profile otherwise no bueno.
Does this not work wit Valet? I have installed the laravel installer AND have correct path.. Still I get the error.
Thanks @phaberest! I found that my bash file was actually ~/.bash_profile
Changing "~" to "$HOME" while using fish fixed the issue for me. Thank you! i.e. set -U fish_user_paths "$HOME/.composer/vendor/bin" $fish_user_paths
This worked for me but my laravel bin was in an odd location. So I suggest if people are struggling to get this work they search for the lavavel bin. find ~/ -type f -name "laravel" Then check your paths after you edit you edit your .bashrc echo $PATH Make sure you have added the path with the laravel folder
|
11

Open your terminal and run these given lines:

For zsh and bash:

export PATH="$HOME/.config/composer/vendor/bin:$PATH"

source ~/.zshrc
source ~/.bashrc

For bash only:

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

source ~/.bashrc

2 Comments

Don't copy your posts, nor make them link only. Either tailor each response for each question, or flag to close as a duplicate.
Sorry, @Frankerz. Now I modify the comment. And thanks.
4

If you put the tilde (~) inside quotes it won't be translated to your home directory. Run this and it should work:

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

1 Comment

This also worked btw
3

For anyone using Homestead I found this one worked for me

export PATH="$PATH:$HOME/.config/composer/vendor"

3 Comments

actually it's export PATH="$PATH:$HOME/.config/composer/vendor/bin" anyway thanks for the clue man :)
Why do I have to use this command every time I create a new project? Is there a way to make this command permanent?
@ColinStadig have you read my answer? Put it in you terminal's config file.
2

Just adding to the accepted answer...

In case you are executing the commands directly on the terminal (in which case the path will remain available till the terminal window or tab closes)

If you mess up the earlier path, you need to open and close the terminal window (or tab)

Example:

first execute (mess up the path in someway)

PATH="test"

then execute

PATH="$PATH:$HOME/.config/composer/vendor/bin"

You will still get the error Now close the terminal window or tab and reopen it and execute

PATH="$PATH:$HOME/.config/composer/vendor/bin"

And the error should be gone!

Comments

1

paste this

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

and restart the termminal.

Comments

1

Check if /root/.composer directory EXISTS, if does NOT exist then install composer like this:

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

And install laravel again, after that your command will work.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.