How to place the ~/.composer/vendor/bin directory in your PATH?

295,653

Solution 1

To put this folder on the PATH environment variable type

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

This appends the folder to your existing PATH, however, it is only active for your current terminal session.

If you want it to be automatically set, it depends on the shell you are using. For bash, you can append this line to $HOME/.bashrc using your favorite editor or type the following on the shell

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

In order to check if it worked, logout and login again or execute

source ~/.bashrc

on the shell.

PS: For other systems where there is no ~/.bashrc, you can also put this into ~/.bash_profile

PSS: For more recent laravel you need to put $HOME/.config/composer/vendor/bin on the PATH.

PSSS: If you want to put this folder on the path also for other shells or on the GUI, you should append the said export command to ~/.profile (cf. https://help.ubuntu.com/community/EnvironmentVariables).

Solution 2

Detailed instructions:

in your ~/.bashrc add these lines:

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

Then reload:

source ~/.bashrc

Check if its added correctly:

echo $PATH

/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/web/bin:~/.composer/vendor/bin

Solution 3

In Ubuntu 16.04 LTS with composer globally installed, this worked for me.

Edit the .bashrc file in your home directory puting the path to the composer bin folder that is located in /your/home/.config/composer/vendor/bin

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

source ~/.bashrc

If not works, verify the path to the composer bin directory and close and reopen the terminal. Otherwise, try to logoff and login in the Ubuntu.

Also works in ubuntu 18.04. Thanks @chifliiiii for your feedback.

Solution 4

For setting the PATH on Yosemite (OS X 10.10.5), use the command below:

echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bash_profile

To reload either quit terminal and start up again or use:

source ~/.bash_profile

Helped me, hope it helps someone else out there!

Solution 5

I did all of the above and it didn't work for me.

I just copied this into my terminal and it worked for me.

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

Related videos on Youtube

which1ispink
Author by

which1ispink

Updated on December 27, 2021

Comments

  • which1ispink
    which1ispink over 2 years

    I'm on Ubuntu 14.04 and I've been trying all possible methods to install Laravel to no avail. Error messages everything I try. I'm now trying the first method in the quickstart documentation, that is, via Laravel Installer, but it says to "Make sure to place the ~/.composer/vendor/bin directory in your PATH so the Laravel executable is found when you run the Laravel command in your terminal." so my question is, how do I do that? This may be a simple question but I'm really frustrated and would appreciate any help.

  • sunnysidedown916
    sunnysidedown916 about 9 years
    Thx! I'm not too familar with unix and this made total sense! (And dollars!)
  • Michiel
    Michiel almost 9 years
    Works like a charm here, on ubuntu 14.04. You might wanna logout/login and/or open a fresh terminal window if things don't seem to work.
  • phaberest
    phaberest over 8 years
    Thank you @forca001 in my .zshrc it was not working using ~ and it finally did with $HOME
  • phaberest
    phaberest over 8 years
    You should use $HOME instead of ~ in the composer path. Not sure about bash, but it is certainly necessary when you're setting it in zsh's .zshrc.
  • Askar
    Askar over 8 years
    Nice! This worked for me as well on Mac OS X El-Captain.
  • waweru
    waweru almost 8 years
    It should be noted that on Ubuntu 16.04 running laravel 5.1, the path is: ~/.config/composer/vendor/bin
  • Abhishek Goel
    Abhishek Goel over 7 years
    @grit45 can you please explain why it worked a little bit
  • JoshP
    JoshP over 7 years
    Alternatively, I needed to edit my ~/.zshrc as I'm using oh-my-zsh with iTerm2. Otherwise... same instructions... cheers!
  • nclsvh
    nclsvh about 7 years
    I have tried this, no luck! Also I do not have a directory called ./composer/vendor. I only have .composer and in there i have a cache folder.. Been searching for 2 days now.
  • nclsvh
    nclsvh about 7 years
    The thing I echo $PATH does not include the composer part.. I have literally added it over 100 times in all the possible ways, rebooted about 5 times an reloaded bashrc.. nothing. Any idea?
  • Brainmaniac
    Brainmaniac almost 7 years
    source ~/.bashrc --- I have to do this each time i should laravel. This is the best answer for me
  • Izac Mac
    Izac Mac almost 7 years
    absolute champion. thanks mate. waisted 10 min trying to do it. your solution worked like a charm
  • CecilMerrell aka bringrainfire
    CecilMerrell aka bringrainfire over 6 years
    echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc was missing the .config directory THEN execute source ~/.bashrc
  • Abdelsalam Shahlol
    Abdelsalam Shahlol over 6 years
    Worked with Parrot OS 3.8
  • ottz0
    ottz0 over 6 years
    This works, when you run composer laravel installer, it changes directory to Changed current directory to /home/username/.config/composer ./composer.json has been updated as per the path in this answer
  • Ken
    Ken over 6 years
    Both .composer/vendor/bin and .config/composer/vendor/bin contain "laravel" for me on Ubuntu 16.04 for what it's worth, so both work.
  • GabMic
    GabMic over 6 years
    This is the one that worked for me on ubuntu 17.10. Thanks.
  • MrTux
    MrTux about 6 years
    This question is about putting some directory on the path and not how to install composer.
  • Christian Bonato
    Christian Bonato almost 6 years
    Works on OS X El Capitan.
  • Ryan Coolwebs
    Ryan Coolwebs over 5 years
    This is the only answer that worked for me on my Mac running OSX Mojave. Thanks heaps!
  • MrTux
    MrTux about 5 years
    What is the improvement to the existing answers?
  • MrTux
    MrTux about 5 years
    What is the improvement to the existing answers?
  • OMi Shah
    OMi Shah over 4 years
    This should be the accepted answer. Worked with MacOS Majave 14.x
  • Sharifur Robin
    Sharifur Robin about 3 years
    you have saved my time, i was searching for 2hr
  • Roman Kozin
    Roman Kozin almost 3 years
    For Linux Mint 20.2 it was $HOME:~/.config/composer/vendor/bin:$PATH
  • Vladimir Vukanac
    Vladimir Vukanac over 2 years
    Get the path by composer it self: stackoverflow.com/a/69125272/2873481
  • Renato Francia
    Renato Francia over 2 years
    Worked like a charm on 20.04.
  • Jet Ezra
    Jet Ezra over 2 years
    Seems to work for me