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?

Dallas Caley
  • 5,367
  • 6
  • 40
  • 69
  • 1
    did you run the commands in the VM? or your machine? I have a similar setup, and run them in my machine – Eduardo Pacios Feb 04 '16 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 – Dallas Caley Feb 05 '16 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) – Eduardo Pacios Feb 07 '16 at 00:45
  • to solve the problem you need to find the compose config files location. And then fix the export PATH http://stackoverflow.com/a/41476969/2652524 – Gujarat Santana Jan 05 '17 at 06:12

7 Answers7

48

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.

phaberest
  • 3,140
  • 3
  • 32
  • 40
  • 1
    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. – Dallas Caley Feb 05 '16 at 23:24
  • Does this not work wit Valet? I have installed the laravel installer AND have correct path.. Still I get the error. – nclsvh Apr 25 '17 at 08:51
  • @NicolasV make sure you installed Valet globally – phaberest Apr 25 '17 at 17:39
  • @phaberest pretty sure I have, followed the Laravel docs.. Anyhow, I can manage with the composer way of installing Laravel. – nclsvh Apr 26 '17 at 07:30
  • 1
    Thanks @phaberest! I found that my bash file was actually `~/.bash_profile` – Taylor Cox Aug 31 '17 at 18:31
  • 1
    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` – jClark Apr 23 '18 at 14:11
  • Great to hear mate ;) – phaberest Apr 24 '18 at 12:58
  • 1
    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 – Dean Oakley Apr 12 '20 at 03:43
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
Md Rasel Ahmed
  • 1,025
  • 9
  • 12
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"
ManiacTwister
  • 311
  • 1
  • 12
3

For anyone using Homestead I found this one worked for me

export PATH="$PATH:$HOME/.config/composer/vendor"
Matt Stephens
  • 922
  • 1
  • 6
  • 24
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!

brucekaushik
  • 377
  • 1
  • 4
  • 16
1

paste this

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

and restart the termminal.

Joel Meza Baca
  • 658
  • 9
  • 13
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.

mzalazar
  • 6,206
  • 3
  • 34
  • 31